Could someone explain to me why I get an error message
saying that ‘TS’ is not defined in the following code?
I get the error with FF.
IE appears to work, but I would like to make it cross-browser compatible.
[code=php]
<html>
<head>
<title>JSON Test</title>
<script type=”text/javascript”>
TS = { // to be put into separate file at a later time
place : [
{‘ids’:’Alley Oop’, ‘win’:7, ‘lose’:3, ‘draw’:0, ‘tot’:0, ‘pts’:0 },
{‘ids’:’Betty Boop’, ‘win’:6, ‘lose’:4, ‘draw’:1, ‘tot’:0, ‘pts’:0 },
{‘ids’:’Clarabel Cow’, ‘win’:5, ‘lose’:5, ‘draw’:0, ‘tot’:0, ‘pts’:0 },
{‘ids’:’Donald Duck’, ‘win’:4, ‘lose’:6, ‘draw’:1, ‘tot’:0, ‘pts’:0 },
{‘ids’:’Elmer Fudd’, ‘win’:3, ‘lose’:7, ‘draw’:0, ‘tot’:0, ‘pts’:0 }
]
}
// Note: No ‘,’ at end of last entries
function Display_Stats() {
// FUNCTION FOR STATS
for (var i=0; i<TS.place.length; i++) {
TS.place[i].tot = TS.place[i].win + TS.place[i].lose + TS.place[i].draw;
TS.place[i].pts = (3 * TS.place[i].win) + TS.place[i].draw;
}
var common_site = ‘Player: ‘;
document.write(‘<table border=”1″><tr><td width=”34″> </td>’);
document.write(‘<td width=”236″> Player </td>’);
document.write(‘<td width=”34″>Win</td><td width=”34″>Lose</td><td width=”34″>Draw</td>’);
document.write(‘<td width=”34″>Total</td><td width=”34″>PTS</td></tr>’);
for (var i=0; i<TS.place.length; i++) {
document.write(‘<tr><td>’+(i+1)+'</td>’);
site = common_site + (i+1) + ‘ : ‘ + TS.place[i].ids;
document.write(‘<td>’+ site + ‘</td>’);
document.write(‘<td>’ + TS.place[i].win + ‘</td>’);
document.write(‘<td>’ + TS.place[i].lose + ‘</td>’);
document.write(‘<td>’ + TS.place[i].draw + ‘</td>’);
document.write(‘<td>’ + TS.place[i].tot + ‘</td>’);
document.write(‘<td>’ + TS.place[i].pts + ‘</td></tr>’);
}
// CLOSE TABLE
document.write(‘</table>’);
}
</script>
</head>
<body onLoad=”Display_Stats()”>
<p />
JSON Test
</body>
</html>