When should the name attribute be used in HTML4 / HTML5?

I know, having read the W3C document for HTML4.01 and HTML5, that the "name" attribute originally existed as a property of the <a> tag so that people can refer to the anchor point in the document.

However, now that all major browser browsers allow you to link any html element within the document using the id attribute, is there any real use for the name attribute? If so, how should I use the name attribute?

+7
html html5
source share
3 answers

One thing that comes to mind is the switches: you should use name to indicate 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> 
+7
source share

The name attribute is required, I think, on input elements (and their friends) ...

 <input type="text" name="email" value="" /> 
+6
source share

Good question ... As mentioned in other answers, one obvious use is for radio buttons , so that only one switch can be selected at a time, as you can see switches in jQuery - select only one?

Along with this, in ASP.Net MVC I found another use of the name attribute. contact was pressed MVC send button

 <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 indicates the name of the element.

The name attribute is used to refer to form data after submitting the form or link to an element in JavaScript.

Tip. Multiple elements can have the same name. This allows you to have multiple buttons with the same name that can send different values ​​when used in a form.

Other links

0
source share

All Articles