Validate - one or more checkboxes
Hi, I'm having a bit of trouble finding the right way to do this:
I have three checkboxes and the user must choose at least one of them.
The code below works, but if the user checks one, the error label is only removed from that particular checkbox (submitting the form works though, so it is only a cosmetic error).
How can I remove the errors from the other checkboxes as well, preferably from within the validation method below.
-
- jQuery.validator.addMethod("oneselected", function(value, element) {
- var optionOne = $('#optionOne')[0];
- var optionTwo = $('#optionTwo')[0];
- var optionThree = $('#optionThree')[0];
- if(optionOne.checked || optionTwo.checked || optionThree.checked) {
- return true;
- } else {
- return false;
- }
- }, "You have to choose at least one of 'One', 'Two' or 'Three' " );