...

IE getElementById uses name not id??

sad69
03-26-2004, 10:52 PM
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 (http://www.zend.com/zend/spotlight/code-gallery-wade7.php#Heading9).

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.

swmr
03-27-2004, 10:05 AM
This might be worth experimenting with: uniqueID Property (http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/uniqueid.asp)

Garadon
03-27-2004, 11:25 AM
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.

liorean
03-27-2004, 11:27 AM
Hmm, doesn't ie actually return a collection of all elements with that id when used multiple times on page?

brothercake
03-27-2004, 12:23 PM
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" :p

Anyway .. the solution is don't use the same value for the ID of one element and the NAME of another.

sad69
03-27-2004, 11:55 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum