View Full Version : random image script

01-15-2004, 10:06 PM
hi :)

was just wondering if anyone knew a script for a random image generator..i cant seem to find one, and i dont know the script :x

ex. i have 3 pictures
when i go to my site... u'd see one of the pictures in the middle, but when u refresh/reload the page.. a different picture would be there.. and yea :D

was just wondering if anyone knew a script for that, and if you could please show me if you did :(

thx in advance ;)

01-15-2004, 10:13 PM
<script type="text/javascript">
onload = function()
var images =

document.images[0].src = images[Math.floor(Math.random()*images.length)];
<img src="blank.png" alt="" />

01-15-2004, 11:15 PM
if u plan on calling ur pictures the same with a simple number increaser the array from above reply becomes redundant: u could then just write.
And this is only my opinion but refering to a specific image in the documents image array by its number is something one should stay away from since it hampers development of at site, use id locating or some other method. That is only my opinion.

onload = function()
var pics=3;
document.getElementById('pic').src ="foo"+Math.floor(Math.random()*pics);

<img src="blank.png" alt="" id="pic" />

I got a quenstion I seen many use this <![CDATA[
but what does it do?