• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

name and id

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it safe to replace name tag with id or is it still best to use both?
If I use id only for which browsers will it work?
Love and thanks,
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They are not interchangeable!

id is used to identify any element in the DOM. It is primarily used in client-side script to reference the elements.

name is used to assign request parameter names to form elements only. It is primarily used on the server to collect the request parameter values. Old-fashioned script might try to use name for referencing on the client, but that's a practice that should no longer be used.
 
Author
Posts: 26
MySQL Database PHP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Bear said, "They are not interchangeable". However, the name attribute is used outside of form elements. It is used is some meta tags and it is also used in the map element. Note that an id attribute can also be used in a map element but must have the same value as the name attribute if both are used.

The name attribute does not have the same restrictions that the id attribute has. Two forms on the same page can both have sub-elements with the same name attribute value. For example:

<form id="form-A" onsubmit="validate(this)"><input name="fullname"/><input type="submit"/></form>
<form id="form-B" onsubmit="validate(this)"><input name="fullname"/><input type="submit"/></form>


And using the same name value binds a bunch of radio buttons into a group. Neither of these uses is possible with the id attribute.

Larry
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jp roberts,
Your post was moved to a new topic.
reply
    Bookmark Topic Watch Topic
  • New Topic