View Single Post
Old Mar 3, 2005 | 12:10 PM
  #2  
boon's Avatar
boon
I'm Finding My Feet Here Now
 
Joined: Jul 2004
Posts: 131
Likes: 0
From: Cleveland
Default

Hi

I've never used dreamweaver, but this should do what you're after.

There are 3 constants you'll need to setup - i've put a "TODO" comment so you can easily see them.

The code assumes all your pics will be the same type (eg .JPG). Simply name them all sequentially starting at 1, e.g. carpic1.jpg, carpic2.jpg etc and away you go.

Good luck,

Boon

Code:
<html>
<head>
</head>

<body>

<script type="text/javascript">

var prefix = "\\img\\car\\carpic";			// TODO set the path to your set of pictures
var suffix = ".jpg";						// TODO set the type of image (assumes they're all the same type)
var num_pics = 10;							// TODO set your max pic number (first assumed to be 1)

// Pick a random number between 1 and num_pics...
var r = Math.random();
var pic = Math.round(r*(num_pics-1))+1;

// debugging only, remove when you're happy :)
document.write("When the page loads, it will show the following image : ")
var name = prefix + pic + suffix;
document.write( name+"
");

// Output the HTML to display your picture...
document.write("<IMG SRC=\"");
document.write( name );
document.write("\" alt=\"");
document.write( name );
document.write("\">");

</script>

</body>
</html>
Reply