How to prevent buttons from submitting forms

Khanpo picture Khanpo · May 31, 2009 · Viewed 725.5k times · Source

In the following page, with Firefox the remove button submits the form, but the add button does not.

How do I prevent the remove button from submitting the form?

Answer

Metafaniel picture Metafaniel · May 31, 2012

You're using an HTML5 button element. Remember the reason is this button has a default behavior of submit, as stated in the W3 specification as seen here: W3C HTML5 Button

So you need to specify its type explicitly:

<button type="button">Button</button>

in order to override the default submit type. I just want to point out the reason why this happens.