File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "id and name" Watch "id and name" New topic
Author

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
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: id and name
     
    Similar Threads
    Hibernate Mapping Types.
    xsd : defining array
    Javascript and PHP
    Iterate List on jsp (struts)
    JPA - Hibernate - query.getResultList() returns 3 null values.