Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Noblesville, IN
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    quick question about form elements with "name" and "id" attributes.

    what is the difference between using the "name" attribute as opposed to using the "id" attribute in form elements? are there advantages to using one over the other?
    Ed Ventura
    Graphic/Web Designer
    www.blackwatercompany.com

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    unless you specifically need something to have an 'id', you should always use 'name' for form elements. Non-named elements don't submit with the form.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Also, form elements not marked with name attributes can't be accessed with DOM0 references (document.forms).

    I would normally discourage anyone from using DOM0, but forms are core accessibility features; you can't let them break like you can with DHTML.

    So use NAME for form elements, but not for anything else.
    Last edited by brothercake; 04-04-2003 at 08:00 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    If you want to reach a single form element through scripting, you use id. If you want to name an element or a group of elements something that you can use in the document.forms array or submit information, you should use name. You can use both and they don't have to be equal.

    Name on img or a tags did have the same meaning as id though - so on them you should always use id. Only on form elements does name have additional/different functionality from id.



    As for DOM0 and the DOM, it's not really the right question - name has an entirely different purpose from id.
    Last edited by liorean; 04-04-2003 at 08:08 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by liorean
    ... stuff ...
    Didn't we just have this conversation?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #6
    New Coder
    Join Date
    Jul 2002
    Location
    Noblesville, IN
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    where? i'd be happy to read that discussion.
    Ed Ventura
    Graphic/Web Designer
    www.blackwatercompany.com

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It was on the evolt.org mailing list; http://lists.evolt.org/archive/Week-...1/subject.html - the thread called "setting the value of a file input "

    It didn't conclude much differently from this, I simply remarked because liorean and I both posted to it.
    Last edited by brothercake; 04-04-2003 at 08:42 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #8
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Now I know why I had that Deja Vu feeling - I HAD done it before ;-)
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •