FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

getElementById

 


DanielXP
I have this code for ajax to load my tutorial ratings,

Code:
<script language="javascript" type="text/javascript">
var xmlHttp
function GetXmlHttpObject(){
var objXMLHttp=null
if (window.XMLHttpRequest){
objXMLHttp=new XMLHttpRequest()
}else if (window.ActiveXObject){
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
function GetTuTRating() {
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert ("Browser does not support HTTP Request")
return
}
document.getElementById('TuTRate').innerHTML = 'Loading..';
var url="http://rmb-scripting.com/gettutrating.php?id=<? echo $id; ?>"
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200 || xmlHttp.status == 0) {
document.getElementById('TuTRate').innerHTML = xmlHttp.responseText;
}
}
};
xmlHttp.send(null);
}
GetTuTRating();
</script>
<div id="TuTRate"></div>


But im getting this error

Quote:
'getElementById(...)' is null or not an object


Please help!

Thanks,
Daniel
dramaking
put <div id="TuTRate"></div> before <script language="javascript" type="text/javascript"> ... </script>

and put those code above inside the <body> tag

which looks like...


Code:


<body>
<div id="TuTRate"></div>


<script language="javascript" type="text/javascript">

var xmlHttp
function GetXmlHttpObject(){ ...
...
...

GetTuTRating();
</script>

</body>

Agent ME
Or, make the page wait 'til its loaded before the scripts start:

Code:

<head>

<script language="javascript" type="text/javascript">

var xmlHttp
function GetXmlHttpObject(){ ...
...
...

GetTuTRating();
</script>
</head>

<body onload="Whatever-function-needs-to-start-first">

<div id="TuTRate"></div>

</body>

DanielXP
Agent ME wrote:
Or, make the page wait 'til its loaded before the scripts start:

Code:

<head>

<script language="javascript" type="text/javascript">

var xmlHttp
function GetXmlHttpObject(){ ...
...
...

GetTuTRating();
</script>
</head>

<body onload="Whatever-function-needs-to-start-first">

<div id="TuTRate"></div>

</body>



Cheers the onload worked Smile
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.