...

View Full Version : innerHTML posting an error



Elcid32
07-24-2006, 10:39 PM
Hello forum:

Being new to Javascript this may seem a silly question for the experts; however, please humor me :o

Can anyone tell me what is "technically" wrong with this code:


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="./styles/vmstyle.css" rel="stylesheet" type="text/css">
<link href="./styles/vmgrid.css" rel="stylesheet" type="text/css">
<link>
<script src="./includes/vmfunctions.js" type="text/javascript"></script>
</head>
<body>
<script>
function vmGrid_buildDataSet(){
//getHTTPObject Function Defined In vmfunctions.js
var http = getHTTPObject();
http.onreadystatechange=function(){
if(http.readystate==4 && http.status==200){
document.getElementByID("testDiv").innerHTML = http.responseText;
}
}
http.open('GET',"cptbrwld.php",true);
http.send(null);
}
</script>
<div id="testDiv"></div>
<script>vmGrid_buildDataSet();</script>
</body>
</html>

------------------------

The problem I am getting is that Javascript is throwing an error on the assignment of the innerHTML line (Object does not support this property or method). I am pulling my hair out here. Thanks.

Shawn S.

Kor
07-25-2006, 06:51 AM
"technically" u could have used an event, onload for instance, instead of calling the function directly

<script type="text/javascript">
function vmGrid_buildDataSet(){
//getHTTPObject Function Defined In vmfunctions.js
var http = getHTTPObject();
http.onreadystatechange=function(){
if(http.readystate==4 && http.status==200){
document.getElementByID("testDiv").innerHTML = http.responseText;
}
}
http.open('GET',"cptbrwld.php",true);
http.send(null);
}
onload=vmGrid_buildDataSet;
</script>

and remove the
<script>vmGrid_buildDataSet();</script>

Elcid32
07-25-2006, 04:44 PM
Hey KOR:

I'm using a function becuase the data is dynamic and the function will be called multiple times based on user input. I was able to figure out what was going on - a document.write fires a document.open, thus the data page shows. using a div container and populating the innerHTML worked much better; however, I've read that using the innerHTML approach is not considered "good programming practice." Could someone elaborate? Thanks.

Shawn

glenngv
07-25-2006, 08:13 PM
The error is in red.

document.getElementByID("testDiv").innerHTML = http.responseText;
It should be document.getElementById.

Kor
07-25-2006, 08:52 PM
gee.. I have not seen that... :o good eye, glenngv...

felgall
07-25-2006, 09:42 PM
Using innerHTML works reasonably well on all modern (and many not so modern0 browsers. It is 100000% better than using document.write and is more appropriate than using the proper DOM calls if the content you are trying to insert already has HTML tags in it.

Elcid32
07-26-2006, 03:32 PM
Stephen, thanks for your reply. I appreciate any information and input while I am on the up-side of this learning curve.

Shawn

Elcid32
07-26-2006, 03:34 PM
The error is in red.

document.getElementByID("testDiv").innerHTML = http.responseText;
It should be document.getElementById.


Glennvg- Thanks for the response- I knew I was studying it too hard. Thanks for entertaining such a trivial question.

Shawn



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum