How do I put random quotes on my web site?

C

Chris Ianson

Thanks Jonathan for a helpful reply.

Jonathan N. Little said:
Don't know what's up with #3 link irt.org, they been around forever, but
#4 would do! Hotscripts has many examples that could be adaptable like:

http://www.hotscripts.com/Detailed/48180.html
Quote Randomizer

Took no effort. It is a very easy concept to code, a little research and
you might learn something. You know the old saying..."Give a man a fish
and he is fed for a day, teach a man to fish and he will never be hungry"
 
J

Jose

I don't recall saying I wanted the page to reload. I only want the quote to
change every xx seconds (it might not be 15!)

Some browsers will reload the page. With HTML that's the only way to do
it (that I know of). And it's still a distraction for something
frivolous. I would not impose this on my viewers.

Jose
 
T

Toby Inkster

Jose said:
Some browsers will reload the page. With HTML that's the only way to do
it (that I know of).

Then you don't know of very much:

<p>
<b>No reloads:</b>
<input id="foo" style="width:100%">
</p>
<script type="text/javascript">
quote = new Array(4);
quote[0] = "I came, I saw, I conquered";
quote[1] = "Men believe that willingly which they wish to be true.";
quote[2] = "All bad precedents begin as justifiable measures.";
quote[3] = "Et tu, Brute.";
function randquote ()
{
var f = document.getElementById("foo");
var q = Math.round(Math.random()*4);
f.value = quote[q];
setTimeout("randquote();", 15000);
}
randquote();
</script>

Ideally, you probably don't want an <INPUT> element, but want to use <Q>
or such. Done easily enough though.
 
J

Jose

Then you don't know of very much: [followed by a javascript example]

I said with HTML.... Is Javascript HTML?

(maybe yes... I don't know, but I'm a purist)

Jose
 
C

Chris Ianson

setTimeout("randquote();", 15000);
}
randquote();
</script>

Ideally, you probably don't want an <INPUT> element, but want to use <Q>
or such. Done easily enough though.

That's great Toby. Here's the actual code I found that worked for the page
refresh, but didn't include your timeout.

Can you help me integrate a timeout function into my existing code below, so
the quote changes say every 45 seconds, and is also randomised on page
refresh please?

<script language="JavaScript">
var howMany = 2
var quote = new Array(howMany+1)
quote[0]="quote1"
quote[1]="quote2"
quote[2]="quote3"
function rndnumber(){
var randscript = -1
while (randscript < 0 || randscript > howMany || isNaN(randscript)){
randscript = parseInt(Math.random()*(howMany+1))
}
return randscript
}
quo = rndnumber()
quox = quote[quo]
document.write(quox)
// End --></script>

Thanks in advance :)
 
C

Chris Ianson

Chris Ianson said:
setTimeout("randquote();", 15000);
}
randquote();
</script>

Ideally, you probably don't want an <INPUT> element, but want to use <Q>
or such. Done easily enough though.

That's great Toby. Here's the actual code I found that worked for the
page refresh, but didn't include your timeout.

Can you help me integrate a timeout function into my existing code below,
so the quote changes say every 45 seconds, and is also randomised on page
refresh please?

<script language="JavaScript">
var howMany = 2
var quote = new Array(howMany+1)
quote[0]="quote1"
quote[1]="quote2"
quote[2]="quote3"
function rndnumber(){
var randscript = -1
while (randscript < 0 || randscript > howMany || isNaN(randscript)){
randscript = parseInt(Math.random()*(howMany+1))
}
return randscript
}
quo = rndnumber()
quox = quote[quo]
document.write(quox)
// End --></script>

Thanks in advance :)

Any ideas Tony or anyone?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top