Default type attribute
Inside form element
The default type attribute value for an element in HTML depends on the context in which it is used.
If the <button>
element is used within a <form>
element and the type
attribute is not explicitly specified, then the default value is submit
.
This means that clicking the button (or pressing enter
) will submit the form data to the server.
Outside form element
If the <button>
element is used outside a <form>
element, or the type
attribute is explicitly set to button
, then the button is considered a generic button with no default behavior.
Submit button outside form
By setting the form
attribute of form control to the id
of a form element, you can associate the control with the form.
This association allows the browser to collect the data entered in the control
and submit it along with the data from the other controls in the form when the form is submitted.
Take a look at the button. Although button
is outside form
element, thanks to form
attribute, button
is a part of the projectForm
form.
Thanks for that, pressing enter having the focus on the form, the form will be submitted.