PDA

View Full Version : changeout images



monkey77
Dec 2nd, 2002, 11:23 PM
i need some code to randomly changeout an image in a page. i want it to be different each time someone comes to the page. anyone have any hints to get me going in the right direction?

thanks!

glenngv
Dec 3rd, 2002, 01:08 AM
<html>
<head>
<title>Random Images</title>
<script>
function setRandomImage() {
var imgPath = '/images/';//image folder, set to empty if the same folder as this page
var arrImgs = new Array('img1.jpg','img2.jpg','img3.jpg');//add as many images
var index = Math.floor(Math.random() * arrImgs.length);
document.images["myImg"].src = imgPath + arrImgs;
}
</script>
</head>
<body onLoad="setRandomImage()">
<img src="[i]defaultImage.jpg" name="myImg">
</body>
</html>

monkey77
Dec 3rd, 2002, 03:01 PM
thanks glenn. you rock!