Hi everyone,
I'm having some big JS problems - my function is making my html code
vanish, and I need help!
Here's the code, try it for yourself. You'll notice that when you
click either links and then look at the source code, it's all gone,
apart from what the function is writing. How can I make the code just
append the result under the links? I cannot use <div> or <layer> tags
(show/hide). Thoughts??
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>
<script language="javascript">
var jsData = new Array();
jsData[0] = {bowl:"I", year:1967, winner:"Packers", winScore:35,
loser:"Chiefs", losScore:10};
jsData[1] = {bowl:"II", year:1968, winner:"Packers", winScore:33,
loser:"Raiders (Oakland)", losScore:14};
jsData[2] = {bowl:"III", year:1969, winner:"Jets", winScore:16,
loser:"Colts (Balto)", losScore:7};
jsData[3] = {bowl:"IV", year:1970, winner:"Chiefs", winScore:23,
loser:"Vikings", losScore:7};
jsData[4] = {bowl:"V", year:1971, winner:"Colts (Balto)", winScore:16,
loser:"Cowboys", losScore:13};
function winner() {
// Step 1 - sort by winner function
function sortByWinner(a, b)
{
a = a.winner.toLowerCase();
b = b.winner.toLowerCase();
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
}
// Step 2 - call the sort by winner function
jsData.sort(sortByWinner);
// Step 3 - print the output of the function
for (var i=0; i<jsData.length; i++)
{
document.write(jsData[i].year + jsData[i].winner +"<p>");
}
}
function year() {
// Step 1 - sort by year function
function sortByYear(a, b)
{
return a.year - b.year;
}
// Step 2 - call the sort by year function
jsData.sort(sortByYear);
// Step 3 - print the output of the function
for (var i=0; i<jsData.length; i++)
{
document.write(jsData[i].year + jsData[i].winner +"<p>");
}
}
</script>
</head>
<body>
<a href="javascript:winner()">Winner</a><br>
<a href="javascript:year()">Year</a><br>
</body>
</html>