I have this code:
// Required fields is an array of objects
required_fields.each(function() {
// Check each field: If it has no value, do nothing.
if( !$(this).val() ) {
return false;
}
// If all the fields are there, do something.
else {
alert('Doing something.');
}
});
I'm sure you can see the problem. Having the alert in the .each() function causes the alert to trigger for every item in the array. But what I want is to only trigger the event if ALL of the array items have a value—that is, if none return false.
What is the correct way to trigger something only if all the array items pass?