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 6 of 6
  1. #1
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts

    IE getElementById uses name not id??

    Hey guys,

    I'm having some troubles understanding something, and wondering if it's a bug in IE or what (I don't have netscape at work...).

    I have a multipage form that is written in PHP/Javascript, and the Javascript takes advantage of DOM. As far as the PHP is concerned, it is merely there to retain values from page to page using fieldforwarder.php.

    So what fieldforwarder does is creates hidden input fields of the old values from the different pages.

    But then I have my actual fields which are not hidden on the same page. So essentially I have two fields with the same name. So on the 'active' field, I assign an id to it so that I can reference it using getElementById().

    However, I'm finding that getElementById() will return the hidden field, which is not what I want!

    I know this because first of all I'm getting the wrong values from my boxes. Secondly, when I get the element, I alert element.getAttribute("id") and it comes up blank (because the hidden fields don't have an id).

    So.... help?

    Thanks,
    Sadiq.

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This might be worth experimenting with: uniqueID Property
    Last edited by swmr; 03-29-2004 at 11:09 PM.
    hmm... ?

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    IE does not make a diffenrence between name and id attribute in getElementById, the 1st element with either attribute set to the searched value will be the element returned.

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Hmm, doesn't ie actually return a collection of all elements with that id when used multiple times on page?
    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
    Yeah it does; stupid thing. Any freshman psyche student could tell that "id" and "name" are not the same - your name is part of your self-identify, which is a facet of "ego" not "id"

    Anyway .. the solution is don't use the same value for the ID of one element and the NAME of another.
    Last edited by brothercake; 03-27-2004 at 01:26 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

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyway .. the solution is don't use the same value for the ID of one element and the NAME of another.
    Yep that's what I'm doing now.. what a piss off though..

    Thanks everyone for your help.

    Sadiq.


  •  

    Posting Permissions

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