Categories
JavaScript Answers

How to disable form auto submit on button click with JavaScript?

Spread the love

To disable form auto submit on button click with JavaScript, we return false in the form submit event handler.

For instance, we write

myForm.onsubmit = () => {
  // ...
  return false;
};

to set the myForm.onsubmit property to a function that returns false to prevent the default form submission behavior.

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 *