JSFiddle - React, Tailwind, and code Playground
by John Grivas
HTML
<input type='checkbox' name='question[0][]' value='0'>
<input type='checkbox' name='question[0][]' value='1'>
<input type='checkbox' name='question[0][]' value='2' checked>
<input type='checkbox' name='question[1][]' value='0'>
<input type='checkbox' name='question[1][]' value='1' checked>
<input type='checkbox' name='question[1][]' value='2'>
<input type='checkbox' name='question[2][]' value='0' checked>
<input type='checkbox' name='question[2][]' value='1' checked>
<input type='checkbox' name='question[2][]' value='2'>
JavaScript
var checkedBoxes = {
0: [],
1: [],
2: []
};
var max = 3;
for (index in checkedBoxes) {
$("input[name='question[" + index + "][]']").each(function () {
$(this).change(function () {
alert("ok");
/*console.log(index);
var checkedNum = $("name='question[" + index + "][]']:checked").length;
alert(checkedNum + " - " + index);*/
});
});
}
/*if (checkedNum == max) {
alert("yes");
}
else
{
alert("no");
}*/
//checkedBoxes[index].push(this.checked);
//after everything:
console.log(checkedBoxes); //a multidimesional array of checked boxes