Reputation: 152945
In this form code what is the role of name=""
attribute?
name="s"
and name="submit"
.
Is it necessary to add?
<form action="/index.php" method="get">
<fieldset>
<legend>Search</legend>
<label for="s"><span>Search WaSP</span>
<input value="" name="s" id="s"></label>
<input type="submit" value="Go!" name="submit" >
</fieldset>
</form>
Upvotes: 3
Views: 1178
Reputation: 1885
name
attribute also used for autocompletion. see the detailed list of names here
https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill
Upvotes: 0
Reputation: 11068
This is how they are represented in the DOM as well.
document.forms[0].s.value
Upvotes: 0
Reputation: 523774
The name
("control name") will be passed into the query string when the form is submitted. This is different from the id
attribute which is used to identify an element uniquely by the UA (browser).
With name
, the query will be like
/index.php?s=&submit=Go!
Without name
, the query will be like
/index.php
Upvotes: 7
Reputation: 285077
That is what's actually sent to the server as the name in a normal form submit.
E.g. the name of the StackOverflow answer field is post-text, so the name sent to the server for this field is post-text.
For a GET or application/x-www-form-urlencoded POST, this will be the left-side of a parameter (name=value).
Upvotes: 0