How can i check using Jquery that from every uniquely named checkboxes group atleast one option is checked ?
These checkboxes are generated dynamically and total numbers of uniquely named checkboxes will vary…
<input type="checkbox" class="mcqcb" name="ans_4[]" value="A">
<input type="checkbox" class="mcqcb" name="ans_4[]" value="B">
<input type="checkbox" class="mcqcb" name="ans_4[]" value="C">
<input type="checkbox" class="mcqcb" name="ans_4[]" value="D">
<input type="checkbox" class="mcqcb" name="ans_5[]" value="A">
<input type="checkbox" class="mcqcb" name="ans_5[]" value="B">
<input type="checkbox" class="mcqcb" name="ans_5[]" value="C">
<input type="checkbox" class="mcqcb" name="ans_5[]" value="D">
<input type="checkbox" class="mcqcb" name="ans_17[]" value="A">
<input type="checkbox" class="mcqcb" name="ans_17[]" value="B">
<input type="checkbox" class="mcqcb" name="ans_17[]" value="C">
<input type="checkbox" class="mcqcb" name="ans_17[]" value="D">
So far, I have tried this:
$('input:checkbox[class=mcqcb][name*="ans_*"]').not(':checked').length
It seems like the only way to do this with jQuery is to use an array to store the grouping data for the checkboxes:
JS:
Demo | Source
Edit:
To keep it within checkboxes only just replace the selector (
$('.mcqcb')) with the selector that you have provided:$('input:checkbox[class=mcqcb]')Demo | Source