Do I need to specify type = "send" to the submit buttons?

Previously, when I had a form with a single submit button, I usually don’t add the type="submit" attribute. I never observed these problems and thought that “send” was the default type for the button, and I could rely on this behavior.

However, w3schools and MDN do not agree if I am right.

w3schools applications:

Tip . Always specify the type attribute for the <button> element. Different browsers may use different default types for the <button> element.

whereas MDN claims:

  • submit : ... This is the default value if the attribute is not specified, or if the attribute is dynamically changed to a null or invalid value.

Who is right and who is wrong - both by specification and in real browsers?

+6
source share
1 answer

In MDN, there are some specification links at the bottom of the article that confirm the correctness of the above: by default, the type of the button submit element.

W3C HTML 4.01 :

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

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

W3C HTML5 :

The type attribute controls the behavior of a button when it is activated. This is an enumerated attribute. The following table lists the keywords and states for the attribute — the keywords in the left column structure for the states in the cell in the second column on the same row as the keyword.

 Keyword | State | Brief description --------+---------------+------------------ submit | Submit Button | Submits the form. reset | Reset Button | Resets the form. button | Button | Does nothing. 

Invalid default value is the state of the submit button.

What W3Schools says is that you should always specify an attribute to ensure as consistent a behavior as possible in browsers. This does not mean that the attribute cannot be omitted legally.

+7
source

All Articles