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

  • Thread starter Elizabeth.Lattanzio
  • Start date
E

Elizabeth.Lattanzio

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
 
D

David Dorward

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.
 
D

Doug Gunnoe

'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
 
D

Doug Gunnoe

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.



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 '}'
 

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

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top