CodeAve.com CodeAve.com - JavaScript - Misc
ASP
JavaScript
·Document Info
·Forms
·Images
·Miscellaneous
·Navigation
·Script Writers
·Contents
·What's New?
CSS
HTML
Maps
Links
Mail List
Search
Sitemap


 


Random Text (IE)
Rotating text ads, a random quote, or most anything can easily be done on the client and not use any scripting on the server side to give a "dynamic" look to your pages.  Actually, once you have random text you can insert most any html and have that become part of a randomized display. The example below has ten text strings that will be randomly selected for display.  A couple of them have some simple text formatting commands to demonstrate the ability to insert html in the text.  There is also a variable (number) that is used to accumulate all of the possible random selections.  So, rather than having to change the maximum value every time you add or remove random text, it will be calculated on each iteration.  Keep n mind, all of your random selections are being fed to the client and it is making a decision on which one to display, so you are serving more text than you would in a server side scenario and it's best not to have scores upon scores of random text possibilities just gumming up the download.
View the Output
Text View
Print View
Mail this Link
Download the Code

<html>
<title>
CodeAve.com(Random JavaScript Text)</title>
<body bgcolor=
"#FFFFFF">
<script language
="JavaScript">
<!--
function random_text()
{};
var random_text = new random_text();
// Set the number of text strings to zero to start
var number = 0;
// Incremental list of all possible Text
random_text[number++] = "<font color='#FF0000'>Random JavaScript Text #1</font>"
random_text[number++] = "Some More Random JavaScript Text #2"
random_text[number++] = "Another Random JavaScript Text #3"
random_text[number++] = "A Different Random JavaScript Text #4"
random_text[number++] = "<b>Random JavaScript Text #5</b>"
random_text[number++] = "<i>Random JavaScript Text #6</i>"
random_text[number++] = "<font color='#00FF00'>Random JavaScript Text #7</font>"
random_text[number++] = "<a href='#'>Random JavaScript Text #8</a>"
random_text[number++] = "<font color='#CC33FF'>Random JavaScript Text #9</font>"
random_text[number++] = "<font color='#0000FF'>Random JavaScript Text #10</font>"
// Create a random number with limits based on the number
// of possible random text strings
var random_number = Math.floor(Math.random() * number);
// Write out the random text to the browser
document.write(random_text[random_number]);
-->
</script>
<br><br>
Click <a href="javascript:history.go(0);">refresh</a> to see more random text.
</body>
</html>

 

 

 



ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
Maps: Map Script Writers | Bing Maps | Google Maps
Privacy Statement

CodeAve.com is hosted by MyHosting.com
Donate Food Online with a Mouse Click at TheHungerSite.com
Donate Land Online with a Mouse Click at TheRainForestSite.com
© 1999 - 2014 CodeAve.com
All Rights Reserved