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

219
Views
How to avoid the user from repeating to fill in the form if there is an error?

Problem: I'm doing a form to be filled by the user. Once the user clicks submit, if there is an error in the form, it will show an alert. However, when the user clicks "ok" the form will reset all the fields that have been filled so the user needs to repeat in fill in the form all over again.

Question: How to fix this so that when the user clicks "ok" the data is still there?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

To stop the page from re-loading add return false; after alert statement, it stops the default action from taking place from the form submit.

alert("Please fill in all mandatory fields");
return false;
about 4 years ago · Juan Pablo Isaza Report

0

You should reset form:

document.getElementById("formId").reset();
about 4 years ago · Juan Pablo Isaza Report

0

The <button> element, when placed in a form, will submit the form automatically unless otherwise specified. You can use the following 2 strategies:

  • Use <button type="button"> to override default submission behavior.
  • Use event.preventDefault() in the onSubmit event to prevent form submission.
var form = document.getElementById("myForm");
function handleForm(event) { event.preventDefault(); } 
form.addEventListener('onSubmit', handleForm);
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!