So in the head tag where it says file one, file two, etc., I type in the image URL. ?
And after each one, do I put a comma?
Yes, that is correct.
If I understand correctly, no image names go into the body script?
Technically you are correct. Though, as I said in my first post, I would recommend you pick one image and put that in the 'src' attribute of the image tag. The reason for this is so that an image will still be displayed if a user has javascript disabled. If a user does have javascript enabled it will be overwritten with the image randomly selected.
What about the linking URL of the image?
You want the image to be a link? Does each image go to the same link or does each image have its own link? I assume you mean multiple links. There are several ways to go about this. You could use two arrays, one to hold the image paths and one to hold the links. You could also you one array that is two-dimensioned, or an array of arrays. The option below utilizes a two dimensioal array.
<html>
<head>
<script type="text/javascript">
function random()
{
//The 3 below can be changed to what ever you want
//depending on the number of images/links you have.
var images = new Array(3);
images[0] = new Array(2);
images[0][0] = "image0.jpg";
images[0][1] = "page0.html";
images[1] = new Array(2);
images[1][0] = "image1.jpg";
images[1][1] = "page1.html";
images[2] = new Array(2);
images[2][0] = "image2.jpg";
images[2][1] = "page2.html";
var index = Math.floor(Math.random() * images.length);
document.getElementById("randomImage").src = images[index][0];
document.getElementById("randomLink").href = images[index][1];
}
</script>
</head>
<body onload="random()">
<a id="randomLink" href="http://www.sitename.com/image.jpg"><img id="randomImage" src="img.jpg" alt="Random Image" /></a>
</body>
</html>
I've tested the code above with some sample images and links. It ran perfectly for me. If you need any help understanding anything in the code above feel free to ask. I enjoy working with HTML, Javascript, and CSS. In my spare time at my internship for school I've been creating a custom message box using Javascript and CSS.