My websites files are all in the same folder, the idea is to have an external javascript file (in the same folder) called by the page when clicked. My below code does not work and I don't know why!
Index.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="javascript.js" language="JavaScript"> </script>
</head>
<body>
<p onclick="randomlinks()">Click</p>
</body>
</html>
Javascript.js
<script type="text/javascript">
function randomlinks()
{
var myrandom=Math.round(Math.random()*5)
var links=new Array()
links[0]="index.html"
links[1]="001.html"
links[2]="002.html"
links[3]="003.html"
links[4]="004.html"
links[5]="005.html"
window.location=links[myrandom]
}
</script>
Note: 001-005.html are in the folder also, please help me. This is infuriating!
Thanks for your quick reply Sam Jones, but that's exactly what I already have and it isn't working
This is already in my index.html, which SHOULD call it, but it isn't
<script src="javascript.js" language="JavaScript"> </script>
If you could me more that would be great, thanks you!
Index.html
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="javascript.js" language="JavaScript"> </script>
</head>
<body>
<p onclick="randomlinks()">Click</p>
</body>
</html>
Javascript.js
<script type="text/javascript">
function randomlinks()
{
var myrandom=Math.round(Math.random()*5)
var links=new Array()
links[0]="index.html"
links[1]="001.html"
links[2]="002.html"
links[3]="003.html"
links[4]="004.html"
links[5]="005.html"
window.location=links[myrandom]
}
</script>
Note: 001-005.html are in the folder also, please help me. This is infuriating!
Thanks for your quick reply Sam Jones, but that's exactly what I already have and it isn't working
This is already in my index.html, which SHOULD call it, but it isn't
<script src="javascript.js" language="JavaScript"> </script>
If you could me more that would be great, thanks you!