spartan2 Posted November 19, 2006 Share Posted November 19, 2006 I'm no good with Javascript, and I've looked all over the place for an easy way to make it so that a line of text is randomly selected and typed out of a bunch. I want to have a random quote appear in a spot on one of my pages. How do I do this? Link to comment Share on other sites More sharing options...
MrAdam Posted November 19, 2006 Share Posted November 19, 2006 this little script allows you to assign a phrase or piece of text (max. 11) and then returns it from the function. function selectRandomText() {var txt = new Array(); txt[0] = "phrase 0"; txt[1] = "phrase 1"; txt[2] = "phrase 2"; txt[3] = "phrase 3"; txt[4] = "phrase 4"; txt[5] = "phrase 5"; txt[6] = "phrase 6"; txt[7] = "phrase 7"; txt[8] = "phrase 8"; txt[9] = "phrase 9"; txt[10] = "phrase 10";// max of 10 phrasesvar num = Math.floor(Math.random()*11);// randomlly selects a phrase in the array between 0 and 10.var selected = txt[num];return selected;} Link to comment Share on other sites More sharing options...
spartan2 Posted November 19, 2006 Author Share Posted November 19, 2006 Thanks. How should I implement it onto the page? Do I just put it where I want the text? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now