I want select question[0] at all
I mean question[0][][][] to question[0][3][6][9]
<input type='checkbox' name='question[0][][][]' value='0'>
<input type='checkbox' name='question[0][][][]' value='1'>
<input type='checkbox' name='question[0][][][]' value='2'>
<input type='checkbox' name='question[0][1][][]' value='0'>
<input type='checkbox' name='question[0][2][][]' value='1'>
<input type='checkbox' name='question[0][3][][]' value='2'>
<input type='checkbox' name='question[0][1][4][]' value='0'>
<input type='checkbox' name='question[0][2][5][]' value='1'>
<input type='checkbox' name='question[0][3][6][]' value='2'>
<input type='checkbox' name='question[0][1][4][7]' value='0'>
<input type='checkbox' name='question[0][2][5][8]' value='1'>
<input type='checkbox' name='question[0][3][6][9]' value='2'>
[1]: https://i.stack.imgur.com/Aq6gW.png
CodePudding user response:
You can use jquery and use attribute starts with selector
$( "input[name^='question[0]']" )
CodePudding user response:
From the answers above I solved my problem. Thanks to everyone who helped.
Below is how it was solved
<div>
<input type='checkbox' name='question[0][][][]' value='0'>
<input type='checkbox' name='question[0][][][]' value='1'>
<input type='checkbox' name='question[0][][][]' value='2'>
<input type='checkbox' name='question[0][1][][]' value='0'>
<input type='checkbox' name='question[0][2][][]' value='1'>
<input type='checkbox' name='question[0][3][][]' value='2'>
<input type='checkbox' name='question[0][1][4][]' value='0'>
<input type='checkbox' name='question[0][2][5][]' value='1'>
<input type='checkbox' name='question[0][3][6][]' value='2'>
<input type='checkbox' name='question[0][1][4][7]' value='0'>
<input type='checkbox' name='question[0][2][5][8]' value='1'>
<input type='checkbox' name='question[0][3][6][9]' value='2'>
<input type='checkbox' name='question[1][][][]' value='0'>
<input type='checkbox' name='question[1][][][]' value='1'>
<input type='checkbox' name='question[1][][][]' value='2'>
<input type='checkbox' name='question[1][1][][]' value='0'>
<input type='checkbox' name='question[1][2][][]' value='1'>
<input type='checkbox' name='question[1][3][][]' value='2'>
<input type='checkbox' name='question[1][1][4][]' value='0'>
<input type='checkbox' name='question[1][2][5][]' value='1'>
<input type='checkbox' name='question[1][3][6][]' value='2'>
<input type='checkbox' name='question[1][1][4][7]' value='0'>
<input type='checkbox' name='question[1][2][5][8]' value='1'>
<input type='checkbox' name='question[1][3][6][9]' value='2'>
</div>
<input type="button" value="abc" id="abc">
$("#abc").click(function() {
console.log("click");
var ab = $("input[name^='question[0]']");
for (let i = 0; i < ab.length; i ) {
const element = ab[i];
element.checked=true;
console.log('checkbox');
}
});