I have simple page with multiple check boxes and radio buttons, This is only validating the first system check box and skipping over the next comm check box. I’m fairly new to js and I’m sure this is a simple fix. Any assistance would be appreciated thanks!!!
if (countSelected(formElement, 'checkbox', 'system[]') == 0) {
alert('Please select System Access');
return false;
}
if (countSelected(formElement, 'radio', 'department') == 0) {
alert('Please choose a Department');
return false;
}
if (countSelected(formElement, 'checkbox', 'comm[]') == 0) {
alert('Please select Comm Access');
return false;
}
return true;
}
How can I get this to validate multiple check boxes? Will I also need to apply the same fix for multiple sets of radio buttons?
I think the problem is that you’re
returning from the function too soon. Try this:This way, it validates everything you want,
alerts what you need, andreturns the validity like you expect.Another option, which instead of alerting for each validation, you can do something like this:
In this case, you get one
alertat the end with all the errors. Might be nicer for the user.