File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes id and name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "id and name" Watch "id and name" New topic

id and name

mark I thomas
Ranch Hand

Joined: Apr 07, 2008
Posts: 86

what's the difference between "id" and "name" ? which one should be used when we access this element via using javascript ?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63838

The id attribute assignes an identifier to any element in the DOM for use in client-side scripting. The name attribute is applicable only to form elements and is used to assign the name for the submission parameter for that form element.

So, in short:
  • id is used in JavaScript on the client
  • name is used on the server to collect request parameters.

  • Older JavaScript used the names as part of client-side addressing, but that's antiquated and fragile and should no longer be done that way.

    [Asking smart questions] [About Bear] [Books by Bear]
    It is sorta covered in the JavaRanch Style Guide.
    subject: id and name
    It's not a secret anymore!