Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
JavaScript: casilla de verificación para habilitar/deshabilitar los botones de radio

¡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>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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')); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!