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

141
Visualizações
How to check if both radio buttons are not checked

I'm trying to validate those radio buttons and notify the user if both of them are unchecked. My function RadioValidation() doesn't work, how can I fix it? Thank you!

    function RadioValidation() {
        var buttons = document.querySelectorAll('input[name="shipmethod"]:checked');
        for (var i = 0; i < buttons.length; i++) {
            if (!buttons[i].checked) {
                alert("NOT CHECKED")
            }
        }
    }
<label class="radiner">
  PickUp
  <input type="radio" name="shipmethod" value="PickUp" required>
  <span class="checkmark"></span>
</label>

<label class="radiner">
  Delivery
  <input type="radio" name="shipmethod" value="Delivery" required>
  <span class="checkmark"></span>
</label>
                            
<button class="btn txt-center" type="submit" id="checkout" onclick="RadioValidation()">Payment</button>

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Try this

function RadioValidation() {
    var buttons = document.querySelector('input[name="shipmethod"]:checked');
    if(buttons)
      console.log(buttons.value);
    else
      alert('Nothing selected');
}
<label class="radiner">
  PickUp
  <input type="radio" name="shipmethod" value="PickUp" required>
  <span class="checkmark"></span>
</label>

<label class="radiner">
  Delivery
  <input type="radio" name="shipmethod" value="Delivery" required>
  <span class="checkmark"></span>
</label>
                            
<button class="btn txt-center" type="submit" id="checkout" onclick="RadioValidation()">Payment</button>

about 4 years ago · Santiago Gelvez 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