JavaScript: Random Quote Generator

Posted on May 18, 2005

{{LEARN JAVASCRIPT HERE}}

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

Rate This script
Hot Scripts

Questions: Email Me

Filed Under JavaScript |

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

11 Comments so far
  1. ihatetyping June 11, 2005 1:00 pm

    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! :D

  2. Spyr July 9, 2005 6:56 pm

    This was exactly what I was looking for! Fantastic and it works great. Thanks for this, it’s seriously much appreciated.

  3. ed chamberlain August 2, 2005 10:32 am

    Many thanks, that really is just the ticket. Funny how some of the cleanest js i’ve seen comes from a PHP site!

  4. Víctor August 4, 2005 1:29 am

    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

  5. Christian September 7, 2005 10:24 am

    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?

  6. Paul December 6, 2005 1:47 pm

    Thanks for the script this will work just perfect to help display a random testimonial for our website. Thanks!

  7. thinkbible September 18, 2006 7:51 pm

    Excellent! Fast, Simple, Great! Barebones and streamlined, this little gem does exactly what I want.

  8. Soruyao September 25, 2006 5:39 pm

    This thing is awesome :D This really made my day easier!

  9. james April 29, 2007 3:52 pm

    thanks for this! is there a limit on the length and number of quotes that you can put?

  10. clarksco April 29, 2007 9:40 pm

    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.

  11. MCE Insurance June 5, 2009 8:31 am

    Nice script, easy to integrate