john2
06-06-2005, 03:23 PM
I'm having a problem with nested functions and onload and the following Javascript functions
<script language="javascript" type="text/javascript">
function writeLayer(layerID,txt){
if(document.getElementById){
document.getElementById(layerID).innerHTML=txt;
else if(document.all){
document.all[layerID].innerHTML=txt;
} else if(document.layers){
with(document.layers[layerID].document){
open();
write(txt);
close();
}
}
}
function updateRating(similarityLevel) {
http.open("GET", url, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
...
writeLayer("overallRating", finalRating);
}
</script>
(I've left out a few functions and some of the code in the fuctions to shorten the post.)
When I call writeLayer with a body onload the <div> get updated.
<body onload="javascript:writeLayer('overallRating','40')">
But when I call updateRating, which then calls writeLayer, from the onload the <div> never is updated.
<body onload="javascript:updateRating(40)">
I know the function is being run because I can add an alert which is displayed.
Anyone know why the <div> wouldn't be updated?
<script language="javascript" type="text/javascript">
function writeLayer(layerID,txt){
if(document.getElementById){
document.getElementById(layerID).innerHTML=txt;
else if(document.all){
document.all[layerID].innerHTML=txt;
} else if(document.layers){
with(document.layers[layerID].document){
open();
write(txt);
close();
}
}
}
function updateRating(similarityLevel) {
http.open("GET", url, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
...
writeLayer("overallRating", finalRating);
}
</script>
(I've left out a few functions and some of the code in the fuctions to shorten the post.)
When I call writeLayer with a body onload the <div> get updated.
<body onload="javascript:writeLayer('overallRating','40')">
But when I call updateRating, which then calls writeLayer, from the onload the <div> never is updated.
<body onload="javascript:updateRating(40)">
I know the function is being run because I can add an alert which is displayed.
Anyone know why the <div> wouldn't be updated?