Click to See Complete Forum and Search --> : help needed


Marty McFly
12-19-2003, 05:26 AM
i need a javascript so that every time i refresh the page the logo will change. I have already uploaded the images. I have four images that i wish to use.

can any one help?

Khalid Ali
12-19-2003, 06:03 AM
1. put the images names in an array
2. get a random number using
Math.random()
3. make sure you don't get random number greater then your array length
4. every time page loads create image that matches the random number in the array index

Gonavitch
06-20-2004, 05:38 PM
Here's some code (JavaScript) for ya:

<script language=JavaScript>
var image_num = Math.floor(Math.random() * 4) + 1;
if (image_num==1) {
document.write("<img src='you_first_random_image_src'>");
}
if (image_num==2) {
document.write("<img src='you_second_random_image_src'>");
}
if (image_num==3) {
document.write("<img src='you_third_random_image_src'>");
}
if (image_num==4) {
document.write("<img src='you_fourth_random_image_src'>");
}
</script>

Just place this code where you wan't your images to appear. And of coarse change the src's of the img tags to wan't you wan't and there you go.

Vladdy
06-20-2004, 05:59 PM
And what happens when JS is disabled? That script above is about the worst way to accomplish the task.
OP: Searching forums before posting saves time for both you and other memebers: http://www.webdeveloper.com/forum/showthread.php?s=&threadid=30679

Gonavitch
06-20-2004, 07:39 PM
Yes, JS can be disabled, but the point is, is that he asked for JavaScript, so.