Sometimes, we want to submit an HTML form without redirection with JavaScript.
In this article, we’ll look at how to submit an HTML form without redirection with JavaScript.
How to submit an HTML form without redirection with JavaScript?
To submit an HTML form without redirection with JavaScript, we prevent the default submit action.
For instance, we write
<form onsubmit="return false">
<!-- ... -->
</form>
to set onsubmit
to return false
to stop the form from redirecting during submission.
Then we’ve to submit the form with our own code.
Conclusion
To submit an HTML form without redirection with JavaScript, we prevent the default submit action.