PDA

View Full Version : does getElementById() work in netscape


kwhubby
11-16-2002, 08:20 AM
does getElementById() work in netscape, or is it just IE. And if its only IE, what substitute will work in both??

boggly
11-16-2002, 11:54 AM
As document.getElementById() is part of the DOM, it will naturally work with any browser that is DOM compliant. So yes, that means it will work with NS 6 or above, but not NS 4 or below--to my understanding IE 5.5 and above also support the method, but I'm not 100% on the actual version number. If you want to achieve an equivalent effect in the older browsers, you will need to use their proprietary BOM's (Browser Objet Models) to access the elements you want.

Hope this helps.

-boggly

RadarBob
11-16-2002, 08:40 PM
to my understanding IE 5.5 and above also support the method, but I'm not 100%
Yes, it works in IE 5.5 for windows. Haven't tried on a Mac.

kwhubby
11-17-2002, 08:28 AM
how do you substitute part or all of an object reference with a variable? Just wondering.

boggly
11-17-2002, 01:51 PM
Well, if you're talking about the DOM, it would be something like the following:

var something = document.getElementById("ElementId");

The BOM's are similar, but withough the getElementById() method of course.

Hope this is what you were asking.

-boggly

kwhubby
11-18-2002, 06:17 AM
no thats not what Im asking. Ive seen in some site were the entire object reference was substituted with a variable
but I forgot how it was done
such as
x = "document.fdsa.asdf.value"
and than was somehow
used to reference an obect
To make this easier to understand:
lets say:

var x = prompt("type in something","")

somebody types the complete syntax for referencing something in the prompt (such as document.fdsa.asdf.value). than what ever the thing that x refers to would be alerted

alert( ((the value of document.fdsa.asdf.value)) )
and lets say document.fdsa.asdf.value = "hello"
so it would alert "hello" and not "document.fdsa.asdf.value"

glenngv
11-18-2002, 06:25 AM
is this what you mean?

var x = prompt("type in something","")
alert(eval(x));

of course, if the input is not a valid javascript expression, it will throw an error.

<edit>
got the 1000th post mark! I'm going nuts :D
</edit>

kwhubby
11-18-2002, 06:50 AM
yes thank you so thats it, eval()!!! ahhhhhhh