Welcome to WebmasterWorld Guest from 54.227.52.24

Forum Moderators: open

Message Too Old, No Replies

Script to change text section

     

Ben502

8:34 pm on Jun 29, 2011 (gmt 0)

5+ Year Member



I am looking for a quick and dirty script to change out a bit of text each time a page loads...for example, say i had 10 quotes. Each time the page loads i would like to load a different quote. i think i would prefer to do this with text instead of making them images. Thoughts?

THanks y'all

penders

9:33 pm on Jun 29, 2011 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Ok, something quick and dirty.... ;)

Save this JavaScript in a file called "random_quotes.js":

/** 
* Random Text / Quotes
* Written to element with ID="text-goes-here"
*/
var quotes = [
"To be or not to be, that is the question!",
"Space - the final frontier!",
"Jack and Jill went up the hill..."
];
var obj = document.getElementById('text-goes-here');
if (obj) {
var index = Math.floor(Math.random() * quotes.length);
obj.innerHTML = quotes[index];
}


Link to this script at the bottom of your HTML page, above the closing </body> tag:
<script type="text/javascript" src="random_quotes.js"></script>


Then, in your page, wherever you want the random text/quote to appear put this:
<div id="text-goes-here"></div>


Refresh your page!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month