Reputation: 3616
I know by reading the W3C documentation for HTML4.01 and HTML5 that the "name" attribute originally existed as a property of the <a>
tag to permit people to link to an anchor point within a document.
However, now that all major browser vendors allow linking to any HTML element within a document via the "id" attribute, is there still any real use for the "name" attribute? If so, how should I be using the "name" attribute?
Upvotes: 7
Views: 1245
Reputation: 22661
Good question... As mentioned in other answers one obvious use is for radio buttons
so that only one radio button can be selected at a time, as you can see in jQuery radio buttons - choose only one?
Along with this, in ASP.Net MVC
I have found another use of the name
attribute. Refer
MVC which submit button has been pressed
<input name="submit" type="submit" id="submit" value="Save" />
<input name="submit" type="submit" id="process" value="Process" />
From http://www.w3schools.com/tags/att_button_name.asp
The name attribute specifies the name for a element.
The name attribute is used to reference form-data after the form has been submitted, or to reference the element in a JavaScript.
Tip: Several elements can share the same name. This allows you to have several buttons with equal names, which can submit different values when used in a form.
Other References
Upvotes: 0
Reputation: 51690
One thing that comes to mind are radio buttons: you have to use name
to specify which ones are part of the same group.
<form>
<input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female
</form>
Upvotes: 7
Reputation: 490647
The name
attribute is required, I think, on input
elements (and their friends)...
<input type="text" name="email" value="" />
Upvotes: 6