Web design gurus?? Help needed???
I'm using Dreamweaver to make a website.
Basicly at the header of each page is a picture of a car. I have been trying to work out how to make it randomly choose a different picture from a libary I have of them on line. So hopefully everytime the page is refreshed, it randomly picks out a new picture to put at the top of the page. But I'm not having much luck as I am shite at Java script.
Anyone know how to do it?
If ya can help that would be soooper
Basicly at the header of each page is a picture of a car. I have been trying to work out how to make it randomly choose a different picture from a libary I have of them on line. So hopefully everytime the page is refreshed, it randomly picks out a new picture to put at the top of the page. But I'm not having much luck as I am shite at Java script.
Anyone know how to do it?
If ya can help that would be soooper
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
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>
Thread
Thread Starter
Forum
Replies
Last Post




