Try making the following changes to that link that was posted by Perad (changes in red)...
Code:
<script language="JavaScript">
<!--
/*
Random Image Link Script
By Website Abstraction (http://www.wsabstract.com)
and Java-scripts.net (http://www.java-scripts.net)
*/
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="img1.gif"
myimages[2]="img2.gif"
myimages[3]="img3.gif"
//specify corresponding links below
var imagelinks=new Array()
imagelinks[1]="http://www.wsabstract.com"
imagelinks[2]="http://www.dynamicdrive.com"
imagelinks[3]="http://www.java-scripts.net"
var captions = new Array()
captions[1] = "Javascript is cool";
captions[2] = "PHP is cooler";
captions[3] = "but Raspberryh is the coolest";
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>' + captions[ry])
}
random_imglink()
//-->
</script>
Or even BETTER, have a div for your caption, and do:
Code:
if (ry==0)
ry=1
document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
document.getElementById("caption").innerHTML = captions[ry];
...(and just make sure you include
into your div tag)
OR if you don't want a particular caption to be associated with an image (in other words, you want the caption to be random AND the image to be random SEPARATELY), then generate two different random numbers for each one, like this:
Code:
var ry=Math.floor(Math.random()*myimages.length)
var rz=Math.floor(Math.random()*captions.length)
if (ry==0)
ry=1
if (rz==0)
rz=1
document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
document.getElementById("caption").innerHTML = captions[rz];
Heather