Google Answers Logo
View Question
 
Q: Javascript needed ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Javascript needed
Category: Business and Money > Consulting
Asked by: roseyman-ga
List Price: $10.00
Posted: 14 Jan 2004 10:14 PST
Expires: 13 Feb 2004 10:14 PST
Question ID: 296414
I am looking for a simple javascript that will switch an image on a
homepage when that page is reloaded. I would like a new image to
appear on the homepage each time it is accessed, either randomly or in
an order. Nothing fancy or heavy.

Request for Question Clarification by serenata-ga on 14 Jan 2004 10:35 PST
Hi Roseyman ~

Do you really need javascript? I know of a dynamite cgi script that
will accomplish what you want without having to worry about whether or
not your visitor has javascript disabled.

Thanks,
Serenata

Clarification of Question by roseyman-ga on 14 Jan 2004 11:27 PST
As long as it works i am happy. Will that work on all servers?

DR

Request for Question Clarification by serenata-ga on 14 Jan 2004 11:31 PST
What server are you on? Unix or Windows?

Serenata

Clarification of Question by roseyman-ga on 14 Jan 2004 13:37 PST
Windows NT

Request for Question Clarification by serenata-ga on 14 Jan 2004 16:13 PST
Hi again Roseyman ~

Here's two scripts which should be pretty easy to install and use on
your servers ... the cgi script had a really easy interface, and cgi
*can* run on a Windows server, but only if it's set up to run cgi. And
if your server isn't it wouldn't do you much good.

I've asked the script's author if he has a version for your server,
but haven't heard from him yet.

In the mean time, here are a couple which should serve your purposes:

1. From The Javascript Source:
   - http://javascript.internet.com/miscellaneous/random-image-rotator.html

and

2. From Dynamic Web Coding - Random Image Rotation
   - http://www.dyn-web.com/javascript/rotate-img/rotate-rand.html


Do these look like the type you can work with easily enough?

Thanks,
Serenata

Clarification of Question by roseyman-ga on 14 Jan 2004 20:36 PST
Nope, I need it to change images when the page is refreshed only, not
randomly while the page is loaded.

Do you know of that code?

Thanks,

DR

Request for Question Clarification by serenata-ga on 14 Jan 2004 21:03 PST
That's the cgi. code .... every time you load the page you get a new
image (or content, you can decide).

Let me see what I can find.

Serenata

Request for Question Clarification by serenata-ga on 14 Jan 2004 22:18 PST
I'm sorry Roseyman ...

All the javascript codes I found were not based on cookies, although I
did find some which were built on time sequences, etc.

But that means every time your visitor comes back, he'd see the same
sequences. The script I had in mind was a marvelous little two lines
of script with a Perl5, cgi-bin interface to add your content. And it
just loops through the content every time anyone accesses the page.

Perhaps some other researcher can find or write what you need.

Sorry about that.

 Serenata

Clarification of Question by roseyman-ga on 15 Jan 2004 15:59 PST
Will the cgi script work on Windows NT? I would use it if it would,
otherwise I'm in trouble. Let me know this last answer and I'll pay
you for your time.

Thanks,

DR

Request for Question Clarification by serenata-ga on 15 Jan 2004 16:37 PST
Hi Roseyman ~

The cgi script would work on your Windows NT server, but only if you
have Perl5 installed.

However, the script is free, the author of the script is a very
well-known and highly respected cgi script writer, Will Bontrager.

Their website is at www.willmaster.com ... The script I'm talking
about (which I have used on a lot of sites) is MasterMerryGoRound.

Here's my suggestion ... 

Their contact information is on this page:

   - http://willmaster.com/contact.shtml

Go ahead and ask him if his script can work on your server ... because
it may very well be able to work with some slight adjustment - I
really don't know.

You can tell him that I suggested his script (yes, they know who I am,
I use their scripts on all the sites I design) ... I don't get
anything from recommending them, except the satisfaction of knowing
I've recommended a relatively easy and genuinely good script to
someone.

If he can help you, he'll tell you ... if not, perhaps he can
recommend something that can help accomplish what you want.

I can't post this as an answer, because I haven't really helped you
solve your problem, but thanks so much for your generous offer!

Good luck, 
Serenata

Clarification of Question by roseyman-ga on 16 Jan 2004 22:21 PST
Ok, talked to the server guy (design guy lingo) and PHP and cgi and
perl are out. I need a javascript or .asp solution. There has to be a
simple javascript code for this. All I want to do is have a different
image show up each time the page is loaded. HELP! Does anyone know a
smart javescript person who can solve this? I'll up the ante to $10,
with a tip to boot!
Answer  
Subject: Re: Javascript needed
Answered By: hailstorm-ga on 16 Jan 2004 23:45 PST
Rated:5 out of 5 stars
 
roseyman,

Here is a javascript solution that will randomly switch between a
certain number of images each time a page is loaded.  In its current
state, it requires that you name your images image1.gif, image2.gif,
and so on until the last numbered image is found.

First, place this script somewhere within the <HEAD> tag of your page.
 It is used to generate a random number used in determining the random
image to load.

<script>
<!--
// The Central Randomizer 1.3 (C) 1997 by Paul Houle (houle@msc.cornell.edu)
// See:  http://www.msc.cornell.edu/~houle/javascript/randomizer.html

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
};

function rand(number) {
        return Math.ceil(rnd()*number);
};

// end central randomizer. -->
</script>

Then, in the area of your <BODY> tag where you wish the image to
appear, paste in the following code.  In the section "rand(10)",
replace 10 with the number of images you have available, and the width
and height sections to match that of the images you are using.

<script language="JavaScript"><!--
document.write('<img src="image' + rand(10) + '.gif" width="400" height="40">');
//--></script>

For more information on how to use random numbers in Javascript to
spice up your site, check out this link from the Internet Related
Technologies site:

http://developer.irt.org/script/random.htm

Search Terms Used:
javascript random number

Resources Referenced:
Internet Related Technologies
http://www.irt.org/index.htm
roseyman-ga rated this answer:5 out of 5 stars and gave an additional tip of: $5.00
Great answer, and thanks! Worked perfectly. Also, thanks to
serenata-ga, who is always more than responsive.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy