document.getElementById() problem

M

Mark Smith

I am getting a strange error in internet explorer, the following code
is working in firefox.

Line 33 displays the id of div, so the div object is ok.

....
33: alert(div.id);
34: container=document.getElementById(div.id+"_container");
....

And the following error occurs on line 34:

---------------------------
Error
---------------------------
A Runtime Error has occurred.
Do you wish to Debug?

Line: 34
Error: Object doesn't support this property or method
---------------------------
Yes No
---------------------------


document.getElementById is supported in IE 7, right?

And even if an object with ID, div.id+"_container" did not exist
(which it does), the worst case should be that it returns null... So
what could possibly be causing this?

Thanks for any help.
 
T

Thomas 'PointedEars' Lahn

Mark said:
I am getting a strange error in internet explorer, the following code
is working in firefox.

Line 33 displays the id of div, so the div object is ok.

...
33: alert(div.id);
34: container=document.getElementById(div.id+"_container");
...

And the following error occurs on line 34:

[...]
Line: 34
Error: Object doesn't support this property or method
[...]

document.getElementById is supported in IE 7, right?
Correct.

And even if an object with ID, div.id+"_container" did not exist
(which it does), the worst case should be that it returns null... So
what could possibly be causing this?

Chances are that you have an element with name or ID "container" in the
document, and you did not declare the `container' identifier in the script
with

var container ...

MSHTML proprietarily makes properties of a host object in the scope chain
out of element names or IDs in the document so that you can refer to the
corresponding element objects by script identifier. However, those
host-defined properties cannot be written to without throwing an exception.

We have discussed this (ad nauseam) before.


PointedEars
 
M

Mark Smith

Mark said:
I am getting a strange error in internet explorer, the following code
is working in firefox.
Line 33 displays the id of div, so the div object is ok.
...
33: alert(div.id);
34: container=document.getElementById(div.id+"_container");
...
And the following error occurs on line 34:
[...]
Line: 34
Error: Object doesn't support this property or method
[...]
document.getElementById is supported in IE 7, right?
Correct.

And even if an object with ID, div.id+"_container" did not exist
(which it does), the worst case should be that it returns null... So
what could possibly be causing this?

Chances are that you have an element with name or ID "container" in the
document, and you did not declare the `container' identifier in the script
with

  var container ...

MSHTML proprietarily makes properties of a host object in the scope chain
out of element names or IDs in the document so that you can refer to the
corresponding element objects by script identifier.  However, those
host-defined properties cannot be written to without throwing an exception.

We have discussed this (ad nauseam) before.

PointedEars

That was it exactly, thanks!

I was pulling my hair out over this, because it worked in IE on simple
pages. But broke when I put it in the symfony framework.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top