English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have 5-10 quotes that I want to put on my website and was wondering if anyone knows of a way that I could have them come up in random order. I only want one quote to show at a time, but is there any way that every time the site was refreshed a new one could pop up? Please let me know if you have any idea how to do this! Thanks!

2006-08-17 02:02:44 · 7 answers · asked by Anonymous in Computers & Internet Programming & Design

7 answers

you can do this a number of ways.

You can do this on the client side by using Javascript. Just include each quote in an array, get a random number in the array range, and print the quote at that index.

You can also do this on the server side if you have the ability. You would need to use PHP, ASP, or some other server side technology.

2006-08-17 02:11:50 · answer #1 · answered by John J 6 · 0 0

The javascript solution others describe will work, but you get the same sequence of quotes each time.

You may want to add a cookie containing the number of the last quote. When the user visits your page again, your javascript code reads the cookie,
increments the quote number,
delivers the next quote,
updates the cookie.

2006-08-17 02:21:31 · answer #2 · answered by sheeple_rancher 5 · 0 0

You can either use JavaScript or a server-side scripting language in conjuction with a database of quotes. JavaScript is easier. Here's the code:

var randomNumber=Math.floor(Math.random()*4)

switch (randomNumber){
case 1:
document.write("Quote 1");
break;
case 2:
document.write("Quote 2")
break;
case 3:
document.write("Quote 3");
break;
}

add more quotes in the same fashion

2006-08-17 02:12:11 · answer #3 · answered by IT Pro 6 · 1 0

You will want to look into some type of random javascript or vbscript to generate a random number that corresponds to one of your quotes. See above.

Link : http://sunniebunniezz.com/coppcarbonell/games/factgenerator/factgenerator.htm

Hope that helps!

2006-08-17 02:12:21 · answer #4 · answered by Special Ed 5 · 0 1

Sample code. Place this in a .js file or inside a tag on your webpage. (Note: The quotes array can be as large as you want it to be.)


var quotes = new Array();

quotes[0] = "Quote 1";
quotes[1] = "Quote 2";
quotes[2] = "Quote 3";
quotes[3] = "Quote 4";
quotes[4] = "Quote 5";

function ShowQuote() {
var number = quotes.length;
var increment = Math.floor(Math.random() * number);
var strTemp = quotes[increment];
document.write(strTemp);
}

2006-08-17 02:10:17 · answer #5 · answered by danny 2 · 0 1

Use Javascript. Check the link for some that you can just cut and paste on to your page.

2006-08-17 02:08:52 · answer #6 · answered by ZCT 7 · 1 0

http://www.google.com/search?hl=en&lr=&q=How+do+I+put+quotes+in+my+website

2006-08-17 02:07:31 · answer #7 · answered by malung786 4 · 0 0

fedest.com, questions and answers