I'm working on form validation, and trying to create reusable code so I can place it as a function and call it. But I'm running into trouble, because one of the items is not like the others.
I have two text inputs, one for first name, one for last name. They have separate names, but the same class. When I leave input.name, I want to run the validation code, and check both .name boxes, changing an icon to a checkmark if both are correct. What I have now does this correctly:
http://jsfiddle.net/KAaUN/2/The problem is, later on, when I have selects and single inputs, the validation needs to be the same statement.
I'd like to get the if statement in the validation down to something like:
- if ( ($( $(this).attr("class").each() ).val() != '') ){
Vs what I have now which is:
- if ( ($("input[name=firstName]").val() != '') && ($("input[name=lastName]").val() != '') ){
Any ideas? I thought .each() would work, but it's not. Any help would be much appreciated!