Make your own free website on

Displaying A Random Image

<title>TITLE HERE</title>
<script language="javascript" type="text/javascript">
raImg = new Array("image1.jpg","image2.jpg","image3.jpg","image4.jpg")
imgCt = raImg.length

function choosePic() {
if (document.images) {
randomNum = Math.floor ((Math.random() * imgCt))
document.myPicture.src = raImg[randomNum]
<body onLoad="choosePic()">
<img src="image1.jpg" name="myPicture" alt="random image">

"image1.jpg","image2.jpg","image3.jpg","image4.jpg" In this section you need to place the URL of each image that you want to display at random. The URL should be between a set of quotation marks, and have no spaces. After each image (except the last) you need to place a comma. Do not add spaces there either.
<body onLoad="choosePic()"> You need to add the onLoad attribute to the body tag like I have in this example. There is no need to edit it.
name="myPicture" Place this inside of the image tag that will be the random image, like I have in the above example.