I.E. jscript error: 'document.getElementById(...)' is null or not anobject.

Discussion in 'Javascript' started by Elizabeth.Lattanzio@gmail.com, Jan 3, 2008.

  1. Guest

    Hi all,

    So I've been searching the various forums out there for an answer to
    this problem, but their seem to be multiple versions. I am using the
    getElementById function in my ajax and though it works fine in
    firefox, it returns the following error in Internet Explorer:
    'document.getElementById(...)' is null or not an object.
    Now one post said its because I.E. is not case sensitive, so I made it
    all lower case and nothing. Don't know what else the problem might
    be, but here is the code:
    ////
    function getMenu(){
    xmlHTTP2=GetXmlHttpObject();
    if (xmlHTTP==null){
    alert ("Your browser does not support AJAX!");
    return;
    }
    url2= "GEPmenu.html";
    xmlHTTP2.onreadystatechange=menuPrint;
    xmlHTTP2.open("GET",url2,true);
    xmlHTTP2.send(null);
    }
    function menuPrint(){
    if (xmlHTTP2.readyState == 4) {
    if (xmlHTTP2.status == 200) {
    xmldoc2 = xmlHTTP2.responseText;
    document.getElementById("menutable").innerHTML = xmldoc2; ///This
    is the problem line
    } else {
    alert('There was a problem with the request.');
    }
    }
    }
    ///
    ///This should be changing the contents of the following table in my
    html (I thought maybe it was a table quirk, but also tried it with a
    div... No go.):
    <table width="170" border="1"
    cellpadding="5" cellspacing="0"
    bordercolor="#CCCCCC" bgcolor="#CC3333" id =
    "menutable">

    </table>

    Any answers?
    Thanks,
    Liz
     
    , Jan 3, 2008
    #1
    1. Advertising

  2. Re: I.E. jscript error: 'document.getElementById(...)' is null or notan object.

    On Jan 3, 3:01 pm, wrote:
    > document.getElementById("menutable").innerHTML = xmldoc2; ///This
    > is the problem line
    > <table width="170" border="1"
    > cellpadding="5" cellspacing="0"
    > bordercolor="#CCCCCC" bgcolor="#CC3333" id =
    > "menutable">


    Live URIs are usually easier to debug then snippits of code. The
    problem might be related to IE having issues with editing the
    innerHTML of table elements (avoid using innerHTML to modify the
    contents of tables).

    You also have a lot of presentational markup there, which should be
    moved into a stylesheet.

    --
    David Dorward
    http://dorward.me.uk/
    http://blog.dorward.me.uk/
     
    David Dorward, Jan 3, 2008
    #2
    1. Advertising

  3. Doug Gunnoe Guest

    Re: I.E. jscript error: 'document.getElementById(...)' is null or notan object.

    > 'document.getElementById(...)' is null or not an object.

    Liz,

    I tried in IE 6 had no problem with getElementById("menutable"),
    except when I tried to modify innerHTML, but I got a different error
    than you so it was probably the way I was doing it.


    > function getMenu(){
    > xmlHTTP2=GetXmlHttpObject();
    > if (xmlHTTP==null){
    > alert ("Your browser does not support AJAX!");
    > return;
    > }
    > url2= "GEPmenu.html";
    > xmlHTTP2.onreadystatechange=menuPrint;
    > xmlHTTP2.open("GET",url2,true);
    > xmlHTTP2.send(null);}
    >
    > function menuPrint(){



    Do you realize that you have a function inside a function here?

    Good luck,

    Doug
     
    Doug Gunnoe, Jan 3, 2008
    #3
  4. Doug Gunnoe Guest

    Re: I.E. jscript error: 'document.getElementById(...)' is null or notan object.

    On Jan 3, 9:41 am, Doug Gunnoe <> wrote:
    > > 'document.getElementById(...)' is null or not an object.

    >
    > Liz,
    >
    > I tried in IE 6 had no problem with getElementById("menutable"),
    > except when I tried to modify innerHTML, but I got a different error
    > than you so it was probably the way I was doing it.
    >
    > > function getMenu(){
    > >         xmlHTTP2=GetXmlHttpObject();
    > >         if (xmlHTTP==null){
    > >                 alert ("Your browser does not support AJAX!");
    > >                 return;
    > >         }
    > >         url2= "GEPmenu.html";
    > >         xmlHTTP2.onreadystatechange=menuPrint;
    > >         xmlHTTP2.open("GET",url2,true);
    > >         xmlHTTP2.send(null);}

    >
    > > function menuPrint(){

    >
    > Do you realize that you have a function inside a function here?
    >
    > Good luck,
    >
    > Doug


    Actually you don't. I did not see the last '}'
     
    Doug Gunnoe, Jan 3, 2008
    #4
    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. =?Utf-8?B?QmlsbHk=?=

    document.getElementById("ReportViewerID") returns null

    =?Utf-8?B?QmlsbHk=?=, Jul 6, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    20,526
    Erik Funkenbusch
    Jul 7, 2006
  2. Cirene
    Replies:
    1
    Views:
    822
    Alexey Smirnov
    Jun 9, 2008
  3. Montezuma's Daughter
    Replies:
    4
    Views:
    373
    Munna
    Jul 19, 2008
  4. suresh
    Replies:
    21
    Views:
    696
    James Kanze
    Sep 16, 2010
  5. Gary Mayor

    document.getElementById comes out NULL help!

    Gary Mayor, Mar 2, 2004, in forum: Javascript
    Replies:
    2
    Views:
    169
    Gary Mayor
    Mar 3, 2004
Loading...

Share This Page