Sometimes, we want to disable form auto submit on button clickwith JavaScript.
In this article, we’ll look at how to disable form auto submit on button clickwith JavaScript.
How to disable form auto submit on button clickwith JavaScript?
To disable form auto submit on button clickwith JavaScript, we set the form’s onsubmit
property to a function that returns false
.
For instance, we write
myForm.onsubmit = () => {
// ...
return false;
};
to set the myForm
form’s onsubmit
property to a function that returns false
.
The default submit behavior will be stopped because we returned false
in the onsubmit
method.
Conclusion
To disable form auto submit on button clickwith JavaScript, we set the form’s onsubmit
property to a function that returns false
.