I’m validating my form for required fields, and wish to replace the class “standard_input” with the class “standard_input_error” but my following code won’t work. Also, is it possible to combine functions so that I don’t need to write a function for each id that requires validation (there are some text fields that don’t require validation, so I can’t use it for the entire form). Thanks in advance.
$('#firstname').blur(function()
{
if( !$(this).val() ) {
$(this).addClass('standard_input_error');
}
});
Firstname * <input type="text" id="firstname" name="firstname" class="standard_input">
Last Name* <input type="text" id="lastname" name="lastname" class="standard_input">
another * <input type="text" id="another" name="another" class="standard_input">
another 2 <input type="text" id="another2" name="another2" class="standard_input">
Field * <input type="text" id="fieldb" name="fieldb" class="standard_input">
Blah blah <input type="text" id="blah" name="blah" class="standard_input">
Checkbox 1* <input type="checkbox" checked="checked" id="cbox1" name="cbox1" />
Blah bla 1 <input type="checkbox" checked="checked" id="blabla" name="blabla" />
Blee blee1* <input type="checkbox" checked="checked" id="blee" name="blee" />
bloblo 1 <input type="checkbox" checked="checked" id="blo" name="blo" />
where ‘validate’ is the class applied to input fields which need validation