I have a form that has 30 multiple dynamic checkboxes with the same name. When one of these checkboxes is selected it should populate a hidden radio button. I have the following code below and it works but only for the very first checkbox in the entire list. How do I get it to select the radio button regardless of what checkbox is selected.
Code:function onToggle(){ if (document.querySelector('#skillset').checked) { // if checked console.log('checked'); document.getElementById("radio-for-checkboxes").checked = true } else { // if unchecked console.log('unchecked'); } } Page HTML <div class="checkboxs-wrapper"> <input id="radio-for-checkboxes" type="radio" name="raido" value="2" required/> <!-- BEGIN parentblockid --> <p><a onclick="showLinks(['box2','boxlink1','boxlink3','boxlink4','boxlink5','boxlink6','boxlink7','boxlink8','boxlink9','boxlink10']); hideLinks(['boxlink2','box1','box3','box4','box5','box6','box7','box8','box9','box10'])" class="boxlink" id="boxlink2">{parentblockid.SBB_TITLE}</a></p> <!-- END parentblockid --> <div id="box2" style="display:none;"> <!-- BEGIN skillsetsa --> <input type="checkbox" name="skillset[]" id="skillset" value="{skillsetsa.SBB_VALUE}" {skillsetsa.SBB_VALUECHECKED} data-role="none" required onclick="onToggle()">{skillsetsa.SBB_TITLE}</p> <!-- END skillsetsa --> </div> </div> Generated HTML <div class="checkboxs-wrapper"> <input id="radio-for-checkboxes" type="radio" name="skillset[]" value="2" required/> <div style="display:none;"> <input type="checkbox" name="skillset[]" value="Equipment" >Equipment<br /> <input type="checkbox" name="skillset[]" value="Housing" >Housing<br /> <input type="checkbox" name="skillset[]" value="Other" >Other<br /> </div>



Reply With Quote

Bookmarks