Multiple Random Image links from a Folder

Hey Ive read through the other forums on the topic, but I haven’t done this in a long time. I am just starting the project so I don’t have much to show for it yet.

What I have is a site with about 10 pictures, each of these pictures needs to be randomly pulled from folders, each picture slot will have its own folder, due to it being categorized. When the picture is clicked i need it to open a new page with the document associated to the picture. Is there a way to do this without having to rewrite the code every time? Because as there are new documents added at the end of each week.

Unfortunately the server I use doesn’t support PHP, but if it has to be done in PHP I can switch.

Like I said though I haven’t messed around with web design in a long time, so if someone could essentially spell this out for me I would be extremely grateful.

It would be easier if you used serverside scripting, like php. But, you could pull it off with javascript alone. If you web server will list the contents of a directory, or can be configured to do this, then you could use javascript to request that url of the directory, and then either parse the raw text, or preferably just walk the dom to extract the needed directory and filenames.

This is pretty inefficient and ugly. Again, serverside script is the best way. But it could work :smiley: You should be pretty familiar with javascript before attempting this.

Ok thanks, I have done random images before, and I found the code I used, the problem is that I had to specify what to randomize, with the amount of files we need to randomize it will be pretty time consuming. I’ll look into learning how to do this in php then. Thanks again.

OK so I have a new problem I got the script to work, which is:

<script type=“text/javascript”>
// Set up the image files to be used.
var theImages = [
‘1.png’,
‘2.png’,
‘3.png’,
‘4.png’,
];

var link = [
‘1.html’,
‘2.html’,
‘3.html’,
‘4.html’
];

function showImage()
{
var r = Math.floor(Math.random() * theImages.length);
document.write(‘<A HREF="’ + link[r] + ‘"><img width=“150” height=“100” src="reports/’+theImages[r] +‘" border=“1” ></a>’);
}

</script>

However sometimes the images are repeated, this shows up in four different cells, I actually use quite a few more images and links, just cut them off to save space. Is there a line of code I can change to stop the random repetition, it doesn’t happen often but it looks stupid when it does.

Thank you