I'm looking to put a random quote script on my new website. I found a very helpful script that does exactly what I want here: <script language="JavaScript"> // ============================================== // Copyright 2004 by CodeLifter.com // Free for all; but please leave in this header. // ============================================== var Quotation=new Array() // do not change this! Quotation[0] = "Time is of the essence! Comb your hair."; Quotation[1] = "Sanity is a golden apple with no shoelaces."; Quotation[2] = "Repent! The end is coming, $9.95 at Amazon."; Quotation[3] = "Honesty blurts where deception sneezes."; Quotation[4] = "Pastry satisfies where art is unavailable."; Quotation[5] = "Delete not, lest you, too, be deleted."; Quotation[6] = "O! Youth! What a pain in the backside."; Quotation[7] = "Wishes are like goldfish with propellors."; Quotation[8] = "Love the river's \"beauty\", but live on a hill."; Quotation[9] = "Invention is the mother of too many useless toys."; // ====================================== // Do not change anything below this line // ====================================== var Q = Quotation.length; var whichQuotation=Math.round(Math.random()*(Q-1)); function showQuotation(){document.write(Quotation[whichQuotation]);} showQuotation(); </script> Code (markup): However, I know I'll be adding more quotes to the database, and since this will appear on every page of my website, I don't want to have to update it multiple times. With that being said, is there a way to make a javascript file in my main directory and then link to that on each page, that way I only need to update one file as opposed to all of them? Thanks for the help!
Create a file named for example: random.js Containing the following code: // ============================================== // Copyright 2004 by CodeLifter.com // Free for all; but please leave in this header. // ============================================== var Quotation=new Array() // do not change this! Quotation[0] = "Time is of the essence! Comb your hair."; Quotation[1] = "Sanity is a golden apple with no shoelaces."; Quotation[2] = "Repent! The end is coming, $9.95 at Amazon."; Quotation[3] = "Honesty blurts where deception sneezes."; Quotation[4] = "Pastry satisfies where art is unavailable."; Quotation[5] = "Delete not, lest you, too, be deleted."; Quotation[6] = "O! Youth! What a pain in the backside."; Quotation[7] = "Wishes are like goldfish with propellors."; Quotation[8] = "Love the river's \"beauty\", but live on a hill."; Quotation[9] = "Invention is the mother of too many useless toys."; // ====================================== // Do not change anything below this line // ====================================== var Q = Quotation.length; var whichQuotation=Math.round(Math.random()*(Q-1)); function showQuotation(){document.write(Quotation[whichQuotation]);} showQuotation(); Code (markup): Then in every page of your website where you want the quote/s to appear, add the following line of code (doesn't matter where, but would recommend within your head tags.): <script src="random.js"></script> Then whenever you want to update the javascript just edit 1 file -> random.js and all the pages would be updated