PDA

View Full Version : Random Images Code


bevans76
08-08-2003, 04:36 PM
Very simple: Say I have 52 images and I would like 2 of those 52 to be displyed at random every time a user visits my page. Does anyone know the code for that? Or know where I can find it? Any help is appreciated.

scoutt
08-08-2003, 06:03 PM
http://www.a1javascripts.com/miscellaneous/randombanner/randombanner.html

iti si a banner rotator but you could modifiy it a little and do it for images.

bevans76
08-11-2003, 11:13 AM
Thanks for the reply but there are a couple of problems with this: 1) I cannot view the example because there are errors in the code and 2) I need something that produces new images once a day not every time the page is refreshed. Can anyone help with that?

scoutt
08-11-2003, 11:23 AM
well then you might have to make your own on that. not many out there that do it once a day. it also might have to be serverside too, like cgi, php, asp.

Dennis
08-13-2003, 07:34 AM
Originally posted by bevans76
Very simple: Say I have 52 images and I would like 2 of those 52 to be displyed at random every time a user visits my page. Does anyone know the code for that? Or know where I can find it? Any help is appreciated.


hi, i'm new... excuse me for my bad english :-)

i'd like to help you, but you should explain better what you want to do:

so, you have 52 images. Where? in an array? (better)

do you want to show 2 random images every day differently or every time the page is reloaded?


bye :)

Dennis
08-13-2003, 07:52 AM
i tried to do something... but perhaps isn't whay you are looking for


try

so, if you want to load 2 random images from an array everytime you load the page,
it il simple:


<script>
function loadRandom(){
images=new Array()
images['0']="first.jpg"
images['1']="second.jpg"
images['2']="third.jpg"
number1=parseInt(Math.random()*images.length)
number2=parseInt(Math.random()*images.length)
while(number2==number1){
number2=parseInt(Math.random()*images.length)
}
document.write("<img src='"+images[number1]+"'><br><img src='"+images[number2]+"'>")

}
</script>
<body onload="loadRandom()">


if you want to load 2 different images every day, it's harder. You need to use, as said
the friend before, the serverside.


if you want to load images from other location (not array), post, and we'll try to do it
in some way (it's possible only in particular conditions)

:-)