I have a form that has multiple sets of checkbox and/or radio groups that are dynamically created from sql data. I need to validate that at least 1 checkbox (or a radio button) is checked in each group. HTML output similar to this:
<td>
<input type="checkbox" name"30001" id"30001-1" class="req_question" value="1">
<input type="checkbox" name"30001" id"30001-2" class="req_question" value="2">
</td>
<td>
<input type="checkbox" name"30002" id"30002-1" class="req_question" value="1">
<input type="checkbox" name"30002" id"30002-2" class="req_question" value="2">
</td>
<td>
<input type="radio" name"30003" id"30003-1" class="req_question" value="1">
<input type="radio" name"30003" id"30003-2" class="req_question" value="2">
</td>
<td>
<input type="radio" name"30004" id"30004-1" class="req_question" value="1">
<input type="radio" name"30004" id"30004-2" class="req_question" value="2">
</td>
I have the following addMethod, but this just checks for 1 button and then all groups are validated:
$.validator.addMethod('req_question', function(value) {
return $('.req_question:checked').size() > 0;
}, 'Please check at least one box.');
I believe that this is grabbing the 'req_question' class and validating all the groups at once. How can I "find" all of the disparate groups and validate them individually, when I have no way to know how many there are, or what they are named?