I found a nice script I'd like to use on a client's site (pasted below) The idea is to generate three random images on the home page that are linked to various site pages. This one allows me to define separate images for each of the three arrays. A link to the working script is
here .
Code:
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!-- Hide script from old browsers
myPix1 = new Array("images/pathfinder.gif","images/surveyor.gif","images/surveyor98.gif")
myPix2 = new Array("images/callisto.jpg","images/europa.jpg","images/io.jpg","images/ganymede.jpg")
function choosePix() {
if (document.images) {
randomNum = Math.floor((Math.random() * myPix1.length))
document.myPicture1.src = myPix1[randomNum]
randomNum = Math.floor((Math.random() * myPix2.length))
document.myPicture2.src = myPix2[randomNum]
}
}
// End hiding script from old browsers -->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="WHITE" onLoad="choosePix()">
<IMG SRC="images/spacer.gif" WIDTH="201" HEIGHT="155" NAME="myPicture1" ALT="some image"><br><br>
<IMG SRC="images/spacer.gif" WIDTH="262" HEIGHT="262" NAME="myPicture2" ALT="some image">
However, I can't seem to get the thing to work on my site. The only thing I did was add another array and plug in my images. Only the transparent "space.gif" is loading. Here's my .js file:
Code:
<!-- Hide script from old browsers
myPix1 = new Array("image/hollandth.jpg","image/nationalth.jpg","image/brennanth.jpg")
myPix2 = new Array("image/nationalth.jpg","image/brennanth.jpg","image/hollandth.jpg")
myPix3 = new Array("image/brennanth.jpg","image/hollandth.jpg","image/nationalth.jpg")
function choosePix() {
if (document.images) {
randomNum = Math.floor((Math.random() * myPix1.length))
document.myPicture1.src = myPix1[randomNum]
randomNum = Math.floor((Math.random() * myPix2.length))
document.myPicture2.src = myPix2[randomNum]
randomNum = Math.floor((Math.random() * myPix3.length))
document.myPicture3.src = myPix3.randomNum]
}
}
// End hiding script from old browsers -->
And here's what's in the html:
Code:
<td><IMG SRC="image/space.gif" WIDTH="158" NAME="myPicture1" ALT="some image"></td>
<td><IMG SRC="image/space.gif" WIDTH="158" NAME="myPicture2" ALT="some image"></td>
<td><IMG SRC="image/space.gif" WIDTH="158" NAME="myPicture3" ALT="some image"></td>
I don't understand why the example code works just fine, yet my nearly identical code doesn't. Any ideas? Sharper eyes?
Thanks in advance,
Tim