Currently, I have a script for validating form information that adds a CSS class of .error (which includes a red border) and applies a shake effect when the input value is less than 1 character.
Now, I also need to implement this validation on various select elements within the form if no option has been selected. What changes should be made to the following code in order to achieve this?
// Check if inputs aren't empty
var fields = $('.validate');
var error = 0;
fields.each(function(){
var value = $(this).val();
if( value.length < 1 || value == field_values[$(this).attr('id')] ) {
$(this).addClass('error');
$(this).effect("shake", { times:3 }, 50);
error++;
} else {
$(this).addClass('valid');
}
});
My knowledge of Javascript / Jquery is limited, and this script was adapted from an online source. You can see it in action on this site, specifically on step 2 of the form where selects can be found.