Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Script to change text section

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

Junior Member

5+ Year Member

joined:Aug 21, 2010
posts: 60
votes: 0

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
9:33 pm on June 29, 2011 (gmt 0)

Senior Member

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

joined:July 3, 2006
posts: 3123
votes: 0

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!

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members