52

What is the standard behavior for when a <button> element is clicked in a form? Will it submit the form?

Question is about tag/element <button>, not <input type=button>.

BBaysinger
  • 6,614
  • 13
  • 63
  • 132
lovespring
  • 19,051
  • 42
  • 103
  • 153

2 Answers2

74

If the button is within a form, the default behavior is submit.

If the button is not within a form, it will do nothing.

BUT BE AWARE!

Always specify the type attribute for the button. The default type for Internet Explorer is "button", while in other browsers (and in the W3C specification) it is "submit".

Taken from http://www.w3schools.com/tags/tag_button.asp

Jón Trausti Arason
  • 4,548
  • 1
  • 39
  • 46
  • `button` with no `type` attribute is submitting in IE11. – Michael Benjamin Jun 04 '16 at 17:40
  • 19
    I can't believe I'm saying this, but I think IE has it right, while everyone else is wrong. I think I just threw up a little. I see that w3 says the default should be `submit`, but logically, `button` makes more sense. – Dan Jones Aug 17 '16 at 13:27
22

Yes it default to the submit type.

type = submit|button|reset [CI]
This attribute declares the type of the button. Possible values:

submit: Creates a submit button. This is the default value.

See: http://www.w3.org/TR/html401/interact/forms.html#h-17.5

So when the button is inside a form it will submit it, when it's not inside a form, it still defaults to submit but does nothing (since there's no form associated with it).

As raRaRa has pointed out below older versions of IE have the button tag default type set to button: http://www.thefutureoftheweb.com/blog/button-wont-submit-in-ie

Ivo Wetzel
  • 46,459
  • 16
  • 98
  • 112