Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-27-2005, 03:07 AM   PM User | #1
harvey
New to the CF scene

 
Join Date: Sep 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
harvey is an unknown quantity at this point
Question Rotating a photo with each reload

I am trying to set up a web page that will load a different photo into the same space with each reload. This will show a different look each time a visitor goes to the site.
Help! I have seen the code before, but naturally, when I need it....can't find it.

Thanks for your help!!
harvey is offline   Reply With Quote
Old 09-27-2005, 04:21 AM   PM User | #2
Vladdy
Senior Coder

 
Join Date: Jun 2002
Location: Nashua, NH
Posts: 1,724
Thanks: 0
Thanked 0 Times in 0 Posts
Vladdy is an unknown quantity at this point
a) Best done on the server side so that users with JS disabled can enjoy that functionality.
b) STFW (or to put it mildly GIYF)
c) I feel altruistic today
Code:
...
<script type="text/javascript">
photos = ['photo1.jpg','photo2.jpg','photo3.jpg'];
function replacePhoto()
  { document.getElementById('randomImage').src = photos[Math.floor(.99*Math.random()*photos.length)];
  }
</script>
</head>
<body onload="replacePhoto()">
...
<img id="randomImage" alt="My image" src="photo0.jpg" />
...
__________________
Vladdy | KL
"Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

Last edited by Vladdy; 09-27-2005 at 04:23 AM..
Vladdy is offline   Reply With Quote
Old 10-01-2005, 05:25 AM   PM User | #3
harvey
New to the CF scene

 
Join Date: Sep 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
harvey is an unknown quantity at this point
Thanks

Thanks!
harvey is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:14 AM.


Advertisement
Log in to turn off these ads.