document.getElementById() problem

Discussion in 'Javascript' started by Mark Smith, Jan 14, 2009.

  1. Mark Smith

    Mark Smith Guest

    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.
     
    Mark Smith, Jan 14, 2009
    #1
    1. Advertising

  2. 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+"_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
     
    Thomas 'PointedEars' Lahn, Jan 14, 2009
    #2
    1. Advertising

  3. Mark Smith

    Mark Smith Guest

    On Jan 14, 2:20 pm, Thomas 'PointedEars' Lahn <>
    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+"_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.
     
    Mark Smith, Jan 14, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Franck
    Replies:
    3
    Views:
    2,438
    Eliyahu Goldin
    Aug 25, 2005
  2. Ferret Face
    Replies:
    3
    Views:
    30,525
    Ferret Face
    Oct 4, 2005
  3. wk
    Replies:
    5
    Views:
    192
    Dietmar Meier
    Apr 22, 2005
  4. Martin
    Replies:
    3
    Views:
    165
  5. Replies:
    4
    Views:
    179
    Jonas Raoni
    Nov 21, 2006
Loading...

Share This Page