I am checking for each required fields in a form. I tried this but it only works for the first input. How can I make it work for each input?
if($(\'[require
You need to grab the value of each element, and if ALL of them are not empty, do the first thing, and if ANY of them are empty, do the second thing, correct?
[untested]
// test if any of the values are not empty
var is_empty = false;
$('[required]').each( function(idx, elem) {
is_empty = is_empty || ($(elem).val() == '');
});
// now do the thing, but only if ALL the values are not empty
if ( ! is_empty) {
$('.button1').fadeIn(0);
$('.button2').fadeOut(0);
}else{
$('.button1').fadeOut(0);
$('.button2').fadeIn(0);
}