tags:

views:

6846

answers:

3

There is no such thing as a stupid question, so here we go: What is the difference between between <input type='button' /> and <input type='submit' />?

+21  A: 

<input type="button" /> buttons will not submit a form - they don't do anything by default. They're generally used in conjunction with JavaScript as part of an AJAX application.

<input type="submit"> buttons will submit the form they are in when the user clicks on them, unless you specifiy otherwise with JavaScript.

Phill Sacre
Also browsers can capture the "Enter" keypress on a form and submit the form automatically if there is a submit button, but not otherwise.
Mr. Shiny and New
They also do that if you have a type="image", which can be used to trigger a form-submission when clicked on.
jishi
Mr. Shiny and New: Forms can be submitted via the enter key without any buttons. It's enough to have focus on a text input, for instance.
_Lasar
There's also an actual button element that can also be used to submit forms when clicked. http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.5
R. Bemrose
You can use BUTTON elements, although (surprise surprise) there are a few issues with them when using Everyone's Favourite Browser (IE). Worth knowing about though.
Phill Sacre
+3  A: 

A 'button' is just that, a button, to which you can add additional functionality using Javascript. A 'submit' input type has the default functionality of submitting the form it's placed in (though, of course, you can still add additional functionality using Javascript).

Aistina
+1  A: 

The question here is maybe more relevant if you asked, "what is the difference between a submit-button and a <button>label</button>", since a <button> also submits the form by default.

jishi
The HTML <button> element doesn't submit a form on its own, mate...
Hexagon Theory
Actually, it does in some browsers. Having a form, without a submit-button but instead a <button> will apply submit-functionality to it. Firefox has this behaviour.
jishi
When reading W3C spec this is actually default behaviour, since buttons has a type-attribute which defaults to "submit".
jishi