chrisgray999
10-12-2002, 11:12 AM
Hi, I have the following javascript which I have created. It reads text from a "database", but I can't get it to work. I would be greatful if you could debug it for me.
page1.htm (excerpt):
<a href="javascript.htm?Javascript">Javascript</a>
<a href="javascript.htm?asp">Asp</a>
javascript.htm:
<html>
<head>
</head>
<body>
<script language="javascript">
<!-- Hide Script from old browsers
Data = new Object();
Text = new Object();
Imge = new Object();
// Number of Keywords which are in the "database"
Data[0] = 3
Data[1] = "Javascript"
Text[1] = "View the latest javascripts here!"
Imge[1] = "javascript.gif"
Data[2] = "Perl"
Text[2] = "View Perl scripts here!"
Imge[2] = "perl.gif"
Data[3] = "CGI"
Text[3] = "Find more information about CGI here"
Imge[3] = "cgi.jpg"
Data[4] = "asp"
Text[4] = "find asp scripts here"
Imge[4] = "asp.gif"
function CheckDatabase() {
var Found = false
var Show = location.search.substring(1);
for(var i=1; i<= Data[0]; i++) {
if(Show == Data[i]) {
Found = true
document.write("<h3>"+Data[i]+"</h3>")
document.write("<center>"+Text[i]+"<br><br><img src="+Imge[i]+">")
}
}
if(!Found)
document.write("Error. Requested URL is invalid, please go back and try again")
}
// End Hiding -->
</script>
</body>
</html>
Im sure there is something really stupid that i have done wrong. Basicaly, the script should take the thing after the "?" on the url and display something according to its value.
Thanks very much for any help,
Chris :)
page1.htm (excerpt):
<a href="javascript.htm?Javascript">Javascript</a>
<a href="javascript.htm?asp">Asp</a>
javascript.htm:
<html>
<head>
</head>
<body>
<script language="javascript">
<!-- Hide Script from old browsers
Data = new Object();
Text = new Object();
Imge = new Object();
// Number of Keywords which are in the "database"
Data[0] = 3
Data[1] = "Javascript"
Text[1] = "View the latest javascripts here!"
Imge[1] = "javascript.gif"
Data[2] = "Perl"
Text[2] = "View Perl scripts here!"
Imge[2] = "perl.gif"
Data[3] = "CGI"
Text[3] = "Find more information about CGI here"
Imge[3] = "cgi.jpg"
Data[4] = "asp"
Text[4] = "find asp scripts here"
Imge[4] = "asp.gif"
function CheckDatabase() {
var Found = false
var Show = location.search.substring(1);
for(var i=1; i<= Data[0]; i++) {
if(Show == Data[i]) {
Found = true
document.write("<h3>"+Data[i]+"</h3>")
document.write("<center>"+Text[i]+"<br><br><img src="+Imge[i]+">")
}
}
if(!Found)
document.write("Error. Requested URL is invalid, please go back and try again")
}
// End Hiding -->
</script>
</body>
</html>
Im sure there is something really stupid that i have done wrong. Basicaly, the script should take the thing after the "?" on the url and display something according to its value.
Thanks very much for any help,
Chris :)