This method will return an error if the ID attribute provided to the method is identical to the name of a variable or a function being used in the javascript code.
This will generate the message "Object doesn't support this property or method"
<SCRIPT>
function fnGetId(){
// Returns the first DIV element in the collection.
var oDiv1=document.getElementById("oDiv1");
}
</SCRIPT>
<DIV ID="oDiv1">Div #1</DIV>
<DIV ID="oDiv2">Div #2</DIV>
<DIV ID="oDiv3">Div #3</DIV>
<INPUT TYPE="button" VALUE="Get Names" >
[jsudds] This isn't a "working" example of the problem. The script here, which was copied from the topic above, does not generate an error message. I tried to implement the behavior you describe, by using the script name and a global object, but both IE6 and IE7 run it flawlessly.
<script type="text/javascript">
function fnGetId()
{
var oDiv1 = document.getElementById("fnGetId");
alert(oDiv1.innerHTML);
var oDiv2 = document.getElementById("window");
alert(oDiv2.innerHTML);
}
</script>
<div id="fnGetId">Div #1</div>
<div id="window">Div #2</div>
<input type="button" value="Get Names" />
Can you provide a repro?
[sglass] There's no doubt this exists. We've been dealing with this issue for the past two days. Turns out we were using this shared library called mootools. Within mootools they had defined a function called getElementById(). Once I renamed this method in mootools, my problem dissappeared. This seems to be plaguing a lot of IE users out there. Hopefully they'll find this and get past it.