HighDots Forums  

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

Javascript JavaScript language (comp.lang.javascript)


Discuss I.E. jscript error: 'document.getElementById(...)' is null or not anobject. in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Elizabeth.Lattanzio@gmail.com
 
Posts: n/a

Default I.E. jscript error: 'document.getElementById(...)' is null or not anobject. - 01-03-2008 , 09:01 AM






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

Reply With Quote
  #2  
Old   
David Dorward
 
Posts: n/a

Default Re: I.E. jscript error: 'document.getElementById(...)' is null or notan object. - 01-03-2008 , 09:06 AM






On Jan 3, 3:01 pm, Elizabeth.Lattan... (AT) gmail (DOT) com wrote:
Quote:
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/


Reply With Quote
  #3  
Old   
Doug Gunnoe
 
Posts: n/a

Default Re: I.E. jscript error: 'document.getElementById(...)' is null or notan object. - 01-03-2008 , 09:41 AM



Quote:
'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.


Quote:
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


Reply With Quote
  #4  
Old   
Doug Gunnoe
 
Posts: n/a

Default Re: I.E. jscript error: 'document.getElementById(...)' is null or notan object. - 01-03-2008 , 09:43 AM



On Jan 3, 9:41*am, Doug Gunnoe <douggun... (AT) gmail (DOT) com> wrote:
Quote:
'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 '}'


Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.