Categories
JavaScript Answers

How to make HTML form submit do nothing with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *