Forum Moderators: open

Message Too Old, No Replies

Randomization script

         

supermanjnk

1:12 am on Jul 8, 2004 (gmt 0)

10+ Year Member



I have a script for random images from a file, however it only uses pictures that i have specified, what would i need to add to it to make it so I can have it pull from a random directory.

<!--
function image() {
};

image = new image();
number = 0;

// imageArray
image[number++] = "<img src='Pictures/1.gif' border='0' width='80' height='60'>"
image[number++] = "<img src='Pictures/2.gif' border='0' width='80' height='60'>"
image[number++] = "<img src='Pictures/3.gif' border='0' width='80'height='60'>"
image[number++] = "<img src='Pictures/4.gif' border='0' width='80' height='60'>"
image[number++] = "<img src='Pictures/5.gif' border='0' width='80 'height='60'>"
// keep adding items here...

increment = Math.floor(Math.random() * number);

document.write(image[increment]);

//-->

Bernard Marx

9:02 am on Jul 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A few things before we get down to business..

You are creating a new image, image. This isn't really appropriate here. You want an array. This still works because the image you create can have indexed properties, so it works equally well.

What is the function, image for? It's empty. If you do try to use it, it won't work, because the global variable name, image, is assigned the image that you create. If you want to use the function later, give it a different name.

I don't think giving file names leading digits is legal on most operating systems either.

Do you want random directories, and random images?
What kind of directory names are you choosing from?