Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > random images

random images
Thread Tools
Fresh-Faced Recruit
Join Date: May 2001
Location: Portland, OR USA
Status: Offline
Reply With Quote
Jan 27, 2002, 03:48 PM
 
I have 3 sets of two images that need to be randomly selected on refresh. The sets of images are right on top of each other in a table. Any suggestions?
     
Senior User
Join Date: May 2001
Location: Nottingham, UK
Status: Offline
Reply With Quote
Jan 28, 2002, 05:05 AM
 
is your website sitting on a unix or nt machine?
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Jan 28, 2002, 06:54 AM
 
Originally posted by jonathan stick:
<STRONG>I have 3 sets of two images that need to be randomly selected on refresh. The sets of images are right on top of each other in a table. Any suggestions?</STRONG>
Sure - a document.write which uses a random number generator.

Say you had image1a.jpg, image1b.jpg, image2a.jpg, image2jpg, etc...

A line like this could work a treat:

&lt;td&gt;

&lt;script language="javascript" type="text/javascript"&gt;&lt;!--

document.writeln('&lt;img alt="Pic1" src="image"'+(Math.round(Math.random()*3))+'a.jpg width="50" height="50"&gt;&lt;img alt="Pic1" src="image"'+(Math.round(Math.random()*3))+'b.jpg width="50" height="50"&gt;');

// --&gt;&lt;/script&gt;

&lt;/td&gt;

This is code I've just put together to illustrate a point - I've not used the Math functions for a bit, so it might not work as expected. I just wanted to show how you could go about it easily. A reference book will fill in the necessary detail. :-)

Hope this helps
Computer thez nohhh...
     
Mac Elite
Join Date: Mar 2001
Status: Offline
Reply With Quote
Jan 28, 2002, 05:34 PM
 
Originally posted by jonathan stick:
<STRONG>I have 3 sets of two images that need to be randomly selected on refresh. The sets of images are right on top of each other in a table. Any suggestions?</STRONG>
This has been covered before.

Use client-side javascript if you really mean random and your audience will be using browsers capable of javascript and displaying images.
     
Fresh-Faced Recruit
Join Date: May 2001
Location: Portland, OR USA
Status: Offline
Reply With Quote
Jan 28, 2002, 06:38 PM
 
I understand that it's javascript I want, I just need a more complex script than anyone seems to be offering. The scripts I've used are fine, totally fine, for one image to be displayed at a time, but I have TWO images and they are in sets, so they need to be randomly selected in sets.
i.e.

Let's say I have one image that says "HELLO" and another placed directly below it that says "CUSTOMERS", now I want to be able to have random greetings load in on refresh. So you'll get something like "HELLO" "CUSTOMERS", "GREETINGS" "FRIENDS", "GOOD DAY" "SIRS" everytime you refresh. Get it? TWO images that have to stay together, or they won't line up.

Does anyone know how to do that client-side?
     
Fresh-Faced Recruit
Join Date: May 2001
Location: Portland, OR USA
Status: Offline
Reply With Quote
Jan 28, 2002, 06:41 PM
 
Oh yea.

It's a unix machine.

I'd like to do this with a simple javascript if possible.
     
Fresh-Faced Recruit
Join Date: May 2001
Location: Portland, OR USA
Status: Offline
Reply With Quote
Jan 29, 2002, 01:11 PM
 
Okay, I got it.

If anyone needs this in the future, here is an easy way to do it:

&lt;script language="javascript"&gt;

images_top = new Array(2);
images_bottom = new Array(2);

images_top[0] = 'gfx/spash_science_logo_bar.jpg'
images_bottom[0] = 'gfx/splash_science_banner.jpg'

images_top[1] = 'gfx/spash_conversion_logo_bar.jpg'
images_bottom[1] = 'gfx/splash_conversion_banner.jpg'

images_top[2] = 'gfx/spash_dict_logo_bar.jpg'
images_bottom[2] = 'gfx/splash_dict_banner.jpg'

index = Math.floor(Math.random() * images_top.length);

document.write("&lt;IMG SRC="+images_top[index]+" width=571 height=99&gt;");
document.write("&lt;IMG SRC="+images_bottom[index]+" width=571 height=88&gt;");

&lt;/script&gt;
     
Junior Member
Join Date: Jan 2002
Location: Apex, NC
Status: Offline
Reply With Quote
Feb 2, 2002, 09:44 AM
 
http://www.berlinmethod.com does it. You could rip off his code.
     
   
Thread Tools
Forum Links
Forum 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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:01 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2