Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72358

jQuery validator is not working for checkbox lists when using CSS class to validate

$
0
0

I have some check boxes like so:

<input class="mandatory" name="Notes8~1" id="Notes8~1" type="checkbox" value="Yes">Option 1<br>
<input class="mandatory" name="Notes8~2" id="Notes8~2" type="checkbox" value="Yes">Option 2<br>
<input class="mandatory" name="Notes8~3" id="Notes8~3" type="checkbox" value="Yes">Option 3<br>

(yes I know the <input> tags are not closed, maybe I need to fix that!)

And I want to require that the user checks at least one of them. So I have this JavaScript:

jQuery.ready({function() {jQuery.validator.addClassRules('mandatory', {required: true});}});

to add validation to the check boxes. However this doesn't work; from stepping through the code it looks like the validation code is executed but it somehow passes even if all the check boxes are blank. How can I require the user to check at least one box? I was able to do it by giving them all the same name Notes8 but that won't work in this app because other code is relying on them having unique names.


Viewing all articles
Browse latest Browse all 72358

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>