Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where Does The "name" Attribute Stand?

Status
Not open for further replies.

AbidingDude

Programmer
Oct 7, 2012
74
US
I've been away from JS for a while. I'm getting back into it for a project. The last time I remember working on something form-related. I remember reading back then that the getElementsByName() method was deprecated for everything except forms.
I go back to w3schools today to refresh my memory, and it says the "name" attribute is deprecated and to use the "id" attribute instead:
[URL unfurl="true"]https://www.w3schools.com/jsref/met_doc_getelementsbyname.asp[/url]
That sounds like it's deprecated for all instances. That sounded a little extreme so I also checked out the Mozilla Developer site:
[URL unfurl="true"]https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByName[/url]
They mention that it can only be used in XHTML documents.
Is the "name" attribute still valid for forms?
 
The name attribute isn't going anywhere any time soon. That's for sure.

As far as I know, the only way to get radio buttons to work as a group is by including the name attribute.

<input type="radio" name="ShoeSize" value="9">9
<input type="radio" name="ShoeSize" value="10">10
<input type="radio" name="ShoeSize" value="11">11

You can give each radio button an id if you choose to. However, if you want the user to only select one shoe size, you must include the name attribute.




-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top