Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > document.getElementById() problem

Reply
Thread Tools

document.getElementById() problem

 
 
Mark Smith
Guest
Posts: n/a
 
      01-14-2009
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+"_contain er");
....

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.
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-14-2009
Mark Smith wrote:

> 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+"_contain er");
> ...
>
> 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
 
Reply With Quote
 
 
 
 
Mark Smith
Guest
Posts: n/a
 
      01-14-2009
On Jan 14, 2:20*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
> Mark Smith wrote:
> > 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+"_contain er");
> > ...

>
> > 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57