JavaScript: Random Quote Generator
Posted on May 18, 2005
I know, I know, it is not PHP and why would I do something in JavaScript that I can do in PHP. I had a need to display a random banner on an HTML page that could not parse PHP. Here is what I wrote.
View the script in action here
First of all, in an effort to keep your web page code clean of a bunch of javascript I suggest calling the script from a file. To do so, place the following call in the location on your page that you wish the random text to appear.
<script language="javascript" src="quotes.js"></script>
Download the JS Random Quote script here (2kb) Current Download Count: 3326
Questions: Email Me
Filed Under JavaScript |
Leave a Comment
If you would like to make a comment, please fill out the form below.

Thanks for sharing your code knowledge. I have been looking for a simple random quote generator to use. Your java script example does exactly what I need for now!
This was exactly what I was looking for! Fantastic and it works great. Thanks for this, it’s seriously much appreciated.
Many thanks, that really is just the ticket. Funny how some of the cleanest js i’ve seen comes from a PHP site!
Great code
I was in need of somehting like this and guess what, I’ll be using it to display some versicles.
–Sounds great! Let me know if you need help with the formatting. –Scott
I love this code! The one i’ve been looking for…
But maybe U could help me.:
I want it to be used so it only changes one time a day? Could it be posible?
Thanks for the script this will work just perfect to help display a random testimonial for our website. Thanks!
Excellent! Fast, Simple, Great! Barebones and streamlined, this little gem does exactly what I want.
This thing is awesome
This really made my day easier!
thanks for this! is there a limit on the length and number of quotes that you can put?
James Wrote:
“is there a limit on the length and number of quotes”
I am not sure. Theoretically, there isn’t a limit. However, I have not tested large quotes and high numbers. If you run into a problem, click the “Support” link in the menu and send me an email.
Nice script, easy to integrate