Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda