Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

72
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!