If you want to view all form elements without specifying them separately, you can do something like:
$('#searchform').submit(function() { $.each($(':input', this), function() { $(this).val($(this).val().replace(' ', '_')); }); });
You may need to pay attention to the type of element and its visibility, inclusion, specific type, etc.
EDIT: I would use Andrew's answer. This was the first decision that appeared in my head. This may ultimately give you a little more control over each field in your form, but Andrew is short and sweet.
source share