I think i just worded the sentence weird above, sorry aobut that "any number of images" comment.
In your code above ---if i was going to have the src image just be a rollover, and use it to call the rndimg's into a div somewhere, and the images could be any size?- is there a workaround for that?..maybe just use a this.div or something to put the rndimages into the div i want?
Main Topics
Browse All Topics





by: basicinstinctPosted on 2006-05-15 at 23:20:32ID: 16688026
Well I don't know why the array would need to handle "any number of images" - have I missed something? It's not like you will be filling it dynamically from a database or anything, you will always know how many images are in it because you will have to type the array initialisation yourself.
"owl.jpg", "flower.gi f","alien. jpg");
Here's an example of how it could be done (note, you will need to change the image names in the array - probably also the directory path too.
<html>
<head>
<title>New Page 1</title>
<script language="JavaScript">
function getRndImg()
{
var imgDir = "images/"
var images = new Array("dog.jpg","cat.jpg",
var newImg = imgDir + images[rnd(images.length -1)];
return newImg;
}
function rnd(max)
{
var rnd = Math.round(max * Math.random());
return rnd;
}
</script>
</head>
<body>
<img src="images/default.jpg" onClick="this.src = getRndImg();">
</body>
</html>