Languages
[Edit]
EN

HTML - prevent button from submitting form

0 points
Created by:
Dexter
660

In this article, we would like to show you how to prevent the button from submitting the form in HTML.

Quick solution:

Note:

To prevent the button from submitting the form set button type to "button"  since its default type is "submit".

 

Practical example

Edit

In this example, we set the button element type to "button" to prevent it from submitting the form.

Alternative solutions

Edit

You can also prevent form from being submitted using preventDefault() method.

or by returning false on submit event:

 

References

Edit
  1. <button>: The Button element - HTML: HyperText Markup Language | MDN

Alternative titles

  1. HTML - prevent button from form submit
  2. HTML - prevent input type submit from submitting form
  3. HTML - prevent submit button from submitting form
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join