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

108
Vistas
Check if input is selected

HTML:

<div class="radio" id="uniform-L1"><span><input type="radio" name="length" class="radio" value="L1" id="L1"></span></div>

JS:

<script>
if(document.getElementById('L1').checked) {
         console.log("chwer");
        }
 </script>

I tried to find what's wrong with my JS but I couldn't. I have no console errors.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Listen for the change event if you want to log "chwer" everytime the radio button is checked:

document.getElementById('L1').addEventListener('change', function() {
  if (this.checked) {
    console.log("chwer");
  }
})
<div class="radio" id="uniform-L1"><span><input type="radio" name="length" class="radio" value="L1" id="L1"></span></div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Select the node with querySelector

function checkSelection() {
    const input = document.querySelector('input[name="length"]');
    if (input.checked) {
        console.log(input.value);
    }
}
<div class="radio" id="uniform-L1">
    <input type="radio" name="length" class="radio" value="L1" id="L1"> Radio
</div>
<button onclick="checkSelection()">Check</button>

about 4 years ago · Juan Pablo Isaza Denunciar

0

I believe the issue is that when your run your JS that would only check to see if the radio button is checked when it loads(which wouldn't be checked). If you want the JS to activate when the radio button changed you'll have to activate an onclick to check when your button has changed and then run the script.

about 4 years ago · Juan Pablo Isaza Denunciar
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