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>Untitl ed Document</title>
<script language="javas cript">
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.toLowe rCase();
b = b.winner.toLowe rCase();
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
}
// Step 2 - call the sort by winner function
jsData.sort(sor tByWinner);
// 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(sor tByYear);
// 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="javascrip t:winner()">Win ner</a><br>
<a href="javascrip t:year()">Year</a><br>
</body>
</html>
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>Untitl ed Document</title>
<script language="javas cript">
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.toLowe rCase();
b = b.winner.toLowe rCase();
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
}
// Step 2 - call the sort by winner function
jsData.sort(sor tByWinner);
// 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(sor tByYear);
// 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="javascrip t:winner()">Win ner</a><br>
<a href="javascrip t:year()">Year</a><br>
</body>
</html>
Comment