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?
CodePudding user response:
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;
CodePudding user response:
You should reset form:
document.getElementById("formId").reset();