Sometimes, we want to make HTML form submit do nothing with JavaScript.
In this article, we’ll look at how to make HTML form submit do nothing with JavaScript.
How to make HTML form submit do nothing with JavaScript?
To make HTML form submit do nothing with JavaScript, we return false
in the submit handler.
For instance, we write
<form onsubmit="return false;">
<input type="submit" value="Submit" />
</form>
to set the onsubmit
attribute to return false;
to stop form submission when we click on the submit button.
Conclusion
To make HTML form submit do nothing with JavaScript, we return false
in the submit handler.