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

130
Vistas
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 Respuestas
Responde la pregunta

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 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