M
Mick White
http://www.mickweb.com/football/aleague/ratings.html
I can't get this to work in IE5.2 Mac, it seems to choke on assigning a
table cell's innerHTML property.
player.item(player.length-1).innerHTML=av;
I'm attempting to add each player's ratings and calculate his average
rating. Appears to work in Safari 1.0.2, Netscape 7.0, and Firefox 0.9
(all Mac).
Can anyone suggest how I can use the heirarchal(nodal) DOM to accomplish
the same end? Or improve the script? All table elements are in place.
Mick
Full script below:
<script type="text/JavaScript">
onload=function (){
if(document.getElementsByTagName){
rs= document.getElementsByTagName("TR");
r=rs.length;
while(r--){
if(r&1){
rs.item(r).style.backgroundColor="#c3d3d3";
}
}
//trouble begins below
var t=document.getElementById("ratings");// The table
var trs=t.getElementsByTagName("TR");
for(b=2;b<trs.length;b++){// skip the first two rows
var player=trs.item(b).getElementsByTagName("TD");
var z=0,q=0;
if(player.length){
for(x=0;x<player.length;x++){
if(!isNaN(parseFloat(player.item(x).innerHTML))){
z+=(+ player.item(x).innerHTML);// seems to work
q++ ;
}
av=Math.round((z/q)*100)/100;// so far so good
}
player.item(player.length-1).innerHTML=av; // not good
player.item(player.length-1).style.fontWeight="bold";
}
}
}
}
</script>
I can't get this to work in IE5.2 Mac, it seems to choke on assigning a
table cell's innerHTML property.
player.item(player.length-1).innerHTML=av;
I'm attempting to add each player's ratings and calculate his average
rating. Appears to work in Safari 1.0.2, Netscape 7.0, and Firefox 0.9
(all Mac).
Can anyone suggest how I can use the heirarchal(nodal) DOM to accomplish
the same end? Or improve the script? All table elements are in place.
Mick
Full script below:
<script type="text/JavaScript">
onload=function (){
if(document.getElementsByTagName){
rs= document.getElementsByTagName("TR");
r=rs.length;
while(r--){
if(r&1){
rs.item(r).style.backgroundColor="#c3d3d3";
}
}
//trouble begins below
var t=document.getElementById("ratings");// The table
var trs=t.getElementsByTagName("TR");
for(b=2;b<trs.length;b++){// skip the first two rows
var player=trs.item(b).getElementsByTagName("TD");
var z=0,q=0;
if(player.length){
for(x=0;x<player.length;x++){
if(!isNaN(parseFloat(player.item(x).innerHTML))){
z+=(+ player.item(x).innerHTML);// seems to work
q++ ;
}
av=Math.round((z/q)*100)/100;// so far so good
}
player.item(player.length-1).innerHTML=av; // not good
player.item(player.length-1).style.fontWeight="bold";
}
}
}
}
</script>