So I have this issue where I need to set a value to a checkbox depending on some variables.
The problem is that I encountered the next naming convention on the HTML I'll be working with:
<input id="jc_1" type="checkbox" name="jc[1]">
<input id="jc_2" type="checkbox" name="jc[2]">
<input id="jc_3" type="checkbox" name="jc[3]">
<input id="jc_4" type="checkbox" name="jc[4]">
To decide which input to select I would normally do:
document.getElementsByName('jc')
Then loop through all of them and decide which one to check, the problem here is that I don't really know how to handle this situation in these specific conditions.
I can't use JQuery and I can't change my HTML markup.
jc[1], any chance you can putjc[]?[]will give you autonumbering.querySelectorAll()should do the trick. A polyfill is available for older browsers.