...

View Full Version : DORAND - Do random when function called...



isaaclloyd
03-24-2005, 12:19 PM
Isn't there an easy command called something like DORAND? I am trying to get a script to display a random image and I can't work with all the other random image scripts. Heres kind of what I am looking for:


function randIMG(){
DORAND:

rand1 = "image1.src='images/box_time.gif'"
rand2 = "image2.src='images/box_time.gif'"
rand3 = "image3.src='images/box_time.gif'"
rand4 = "image4.src='images/box_time.gif'"

ENDDORAND:
}


Something like that. Any comments or suggestions would greatly be apreciated. Thanks.

afru
03-24-2005, 06:09 PM
Hi,

Here is js code...



<script language="JavaScript">

function randomImage(){
var numofimages=5;
var randomnum = Math.floor(Math.random() * numofimages);
document.getElementById("myimg").src="images/image"+randomnum+".jpg";
}
window.onLoad=randomImage();
</script>


Add the following code to your body tag where u need the image.



<img src="images/image1.jpg" id="myimg">


Be sure to provide images with image1.jpg, image2.jpg......etc...

Have fun. :)

Afru.

isaaclloyd
03-26-2005, 07:05 PM
you said: var numofimages=5; now when javascript does the math, will that include the number 0?

Thanks,

~Isaac Lloyd~



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum