¡ESTOY TAN CERCA! por defecto, los botones están habilitados. también, cuando está marcado, ambos están habilitados, pero cuando no está marcado, solo uno está deshabilitado.
Lo quiero para que cuando la casilla de verificación esté marcada, ambos botones de opción estén habilitados. y cuando no está marcado, ambos botones de radio están deshabilitados.
no jquery por favor
JS:
var sipch = document.querySelector("input[name=sip]"); sipch.addEventListener("change", function (event) { if (event.currentTarget.checked) { document.querySelector("input[name=protocol]").removeAttribute("disabled"); } else { document.querySelector("input[name=protocol]").setAttribute("disabled", "disabled"); } });HTML:
<!DOCTYPE html> <html lang="en"> <body> <form id="myForm" onsubmit="goPVFive(event)" method="get"> <div id="pBFContainer" class="container"> <div id="bodyFOption1"> <input type="checkbox" name="sip" value="true">Would you like to include establishing the SIP session test?<p> <input type="radio" class="testD" name="protocol" value="udp" disable/>UDP <input type="radio" class="testD" name="protocol" value="tcp" disable/>TCP <label class="testD">(UDP is most Common)</label> </div> <div id="bodyFOption2"> <input type="checkbox" name="fWallInt" value="true">Would you include SIP ALG firewall interference test" </div> </div> <input type="submit" id="subButton" value="Next..." /> </form> </body> <script type="text/javascript" src="evalportalp1.js"></script> </html>Debe usar querySelectorAll y luego recorrer los resultados, deshabilitar/habilitar cada uno de ellos:
if (event.currentTarget.checked) { document.querySelectorAll('input[name=protocol]') .forEach((elem) => elem.removeAttribute('disabled')); } else { document.querySelectorAll('input[name=protocol]') .forEach((elem) => elem.setAttribute('disabled', 'disabled')); }