Computers, Consoles and I.T. Post all computer related chat in here for our I.T techies to help with. Please be aware that any discussions related to piracy will be removed and render the member liable to a possible ban. Piracy renders PassionFord Admin liable for prosecution, as well as its members.

Web design gurus?? Help needed???

Thread Tools
 
Search this Thread
 
Old Mar 2, 2005 | 11:28 AM
  #1  
MadMac's Avatar
MadMac
Thread Starter
15K+ Super Poster!!
 
Joined: Apr 2004
Posts: 16,505
Likes: 1
From: Croydon
Default 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
Reply
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
Old Mar 3, 2005 | 12:16 PM
  #3  
MadMac's Avatar
MadMac
Thread Starter
15K+ Super Poster!!
 
Joined: Apr 2004
Posts: 16,505
Likes: 1
From: Croydon
Default



Thank you thank you!!! Just what I was after

And soo much simpler than the others I have seen
Reply
Old Mar 3, 2005 | 12:22 PM
  #4  
boon's Avatar
boon
I'm Finding My Feet Here Now
 
Joined: Jul 2004
Posts: 131
Likes: 0
From: Cleveland
Default

No problem. I'm a simple person, so everything I do is simple...
Reply
Old Mar 3, 2005 | 12:24 PM
  #5  
MadMac's Avatar
MadMac
Thread Starter
15K+ Super Poster!!
 
Joined: Apr 2004
Posts: 16,505
Likes: 1
From: Croydon
Default

best way to do it when it comes to programming

Been so long thou I can't remember how to do it
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
da52rkn
Ford Focus Range
3
Aug 21, 2015 04:41 PM
jc1989rs
Ford Sierra/Sapphire/RS500 Cosworth
5
Aug 15, 2015 04:58 PM
col93saphcos
Ford Sierra/Sapphire/RS500 Cosworth
5
Aug 7, 2015 03:21 PM




All times are GMT. The time now is 07:29 AM.