Random Picture Generator in a Website? Help

neomits

Diamond Member
Aug 18, 2001
3,228
0
76
Can some one give me the HTML code or a script to display a random picture generator? Thanks
 

jjones

Lifer
Oct 9, 2001
15,424
2
0
I'm not sure if this is what you're looking for but this will show a random picture whenever someone opens the page or refreshes the page.

Place this in the head:

<script LANGUAGE="JavaScript">
<!--
function get_image() {

var numImages = 8;
var rndnum = Math.round(Math.random() * (numImages-1))+1 ;
var selectedImage = "image" + rndnum + ".gif" ;

document.write("<IMG SRC=\"rotate/" + selectedImage + "\" WIDTH=\"321\" HEIGHT=\"65\">") ;
}
//-->
</script>

then place this in the body in the location where you want the picture to be:

<script>get_image();</script>

notes:

the number of images is set to 8 but that can be changed to whatever you want.
this line: var selectedImage = "image" + rndnum + ".gif" ;
means your images should be named image1.gif, image2.gif, etc. change this as appropriate but all images should be named the same except for the number and all should be of one type such as gif or jpg.
img src shows "rotate/" as the subdirectory where the images are located; change as appropriate.
change width and height as appropriate.