I’d like to figure out how to write something like the following to validate single check boxes. There could be just one on the form or many separate ones. The example below doesn’t work.
Thank you!
// -----------------------------------------------
// CHECK SINGLE CHECKBOX
// -----------------------------------------------
$('.mcCbxRequired').each(function() {
var mcCbxCheck = $(this);
if(mcCbxCheck.is(':checked')) {
alert('checked');
// do something here ...
}
else{
alert('not checked');
return false;
}
});
A couple things:
Each applicable checkbox must have the
mcCbxRequiredclass. If neither alert shows, the problem must be because your checkbox does not have this class.You are
returningfalsein both cases. That doesn’t really make sense with validation, so you should change the relevant part of your code to this:Code: