You already know that a form is submitted
when a button is clicked. Here, however,
there are nuances. The button must have
the type
attribute set to
submit
:
<form>
<input name="test1">
<input name="test2">
<input type="submit">
</form>
A form will also be submitted by the
button
tag with the type
attribute set to submit
:
<form>
<input name="test1">
<input name="test2">
<button type="submit">btn</button>
</form>
A form will also be submitted if you put
focus in any of the inputs and press
Enter
.
The button with the type
attribute
set to button
is used as a page
element and will not submit a form:
<form>
<input name="test1">
<input name="test2">
<input type="button">
</form>
The button
tag will work
in the same way:
<form>
<input name="test1">
<input name="test2">
<button>btn</button>
</form>
Button with the type
attribute set
to reset
will clear a completed
form:
<form>
<input name="test1">
<input name="test2">
<input type="reset">
<input type="submit">
</form>
Correct the following code so that a button submits a form to the server:
<form>
<input name="name">
<input name="surn">
<button>submit</button>
</form>