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

76
Vistas
How come my simple checkbox form is not completing its action upon submitting

Its a simple form with a action that should go to the "nextPage.html". it only has 1 input which is a checkbox and a submit button.

const form = document.getElementById('form')
const checkbox = document.getElementById('checkbox')
const message = document.getElementById('message')

form.addEventListener('submit', function validateCheckbox(e) {
    e.preventDefault()
    if (checkbox.checked === true) {
        message.innerHTML = 'Done'
    }
    else {
        message.innerHTML = 'Please check the box to continue!'
    }
})
 <div class="container">
                <form method="post" action="nextPage.html" id="form">
                    <label for="checkbox">By continuing, I agree that I have read and understand the terms of service.</label> <br>
                    <input type="checkbox" id="checkbox">
                    <button type="submit">Submit</button>
                    <h5 id="message"></h5>
                </form>
                    
            </div>

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

0

e.currentTarget.submit(); will "manually" submit the form after you've verified that the checkbox is checked. Also side-note, it is always recommended to include semicolon line terminations.

const form = document.getElementById('form');
const checkbox = document.getElementById('checkbox');
const message = document.getElementById('message');

form.addEventListener('submit', function validateCheckbox(e) {
  e.preventDefault();
  if (checkbox.checked === true) {
    message.innerHTML = 'Done';
    e.currentTarget.submit();
  } else {
    message.innerHTML = 'Please check the box to continue!';
  }
})
<div class="container">
  <form method="post" action="nextPage.html" id="form">
    <label for="checkbox">By continuing, I agree that I have read and understand the terms of service.</label> <br>
    <input type="checkbox" id="checkbox">
    <button type="submit">Submit</button>
    <h5 id="message"></h5>
  </form>
</div>

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