Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
JavaScript How to check if radiobutton is checked or not?

I'm going to put on my website simple radiobutton. His role is only to have value 'on' if checked or 'off' if not checked.

home.html

<input type="radio" id="radio1" class='radio-button' value="off">
<label >Radio1</label>
<br>
<input type="radio" id="radio2" class='radio-button' value="off">
<label >Radio2</label>

I wrote a loop in my js file code to iterate through the inputs and my goal is to change value to 'on' if checked.

myJs.js

const radioButtons = document.getElementsByClassName('radio-button')
for (let radio of radioButtons){if (radio.checked){ radio.value='on'}

But it doesn't work. Value stays 'off' even if radiobutoon is checked. Any idea what am I doing wrong?

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda