Random Javascript
Written by Administrator   
Saturday, 09 December 2006
Javascript Random Saying: Create a random saying each time the page is loaded!  This is an easy way to create dynamic content without having to program a PHP or ASP script for your page.  The actual random part is done on the user's machine.  The downside of using a Javascript for this is that the search engines do not look at the Javascript. Javascript Random Saying: Create a random saying each time the page is loaded!  This is an easy way to create dynamic content without having to program a PHP or ASP script for your page.  The actual random part is done on the user's machine.  The downside of using a Javascript for this is that the search engines do not look at the Javascript.

Cut and paste the following code to the top of your html page:

<script language="Javascript">
// Create the array - random changing text, (c) 2005 Two Brothers Software.
var tbstagline = new Array();
tbstagline[0] = "Place stament one here";
tbstagline[1] = "Place stament two here";
tbstagline[2] = "Place stament three here";
tbstagline[3] = "Place stament four here";
function randomNumber(n) {
number = Math.floor(Math.random() * (n + 1));
return number;
}
</script>


If you want to add more lines be sure to number them accordingly starting with [0]

Place this portion at the point in the HTML where you want the script to read.

<script language="JavaScript">
// Display random changing text, (c) 2005 Two Brothers Software.
document.write(tbstagline[randomNumber(tbstagline.length - 1)]);
</script>

Feel free to use this script in it's any way you would like as long as you like. Make sure that all quotes inside the random tagline ARE single quotes.

This is what this code looks like RANDOM TEXT PAGE

To create a tagline with a <a href> tag use the following modifications:

tbstagline[0] = "<a href='http://www.websitename1.com'>Place statement one here</a>";
tbstagline[1] = "<a href='http://www.websitename2.com'>Place statement two here</a>";
tbstagline[2] = "<a href='http://www.websitename3.com'>Place statement three here</a>";
tbstagline[3] = "<a href='http://www.websitename4.com'>Place statement four here</a>";

Having trouble with cut and paste? Download a .zip file of the Random Sayings Java Script.

Javascript Random Images: Create a random images each time the page is loaded!

Cut and paste the following code to the top of your html

<script language="Javascript">
// Create the array - random changing images, (c) 2005 Two Brothers Software.
var tbstagline = new Array();
tbstagline[0] = "<img src='img1.jpg' alt='' width='wdth' height='hght'>";
tbstagline[1] = "<img src='img2.jpg' alt='' width='wdth' height='hght'>";
tbstagline[2] = "<img src='img3.jpg' alt='' width='wdth' height='hght'>";
tbstagline[3] = "<img src='img4.jpg' alt='' width='wdth' height='hght'>";
function randomNumber(n) {
number = Math.floor(Math.random() * (n + 1));
return number;
}
</script>


If you want to add more lines be sure to number them accordingly starting with [0]

Place this portion at the point in the HTML where you want the images displayed.

<script language="JavaScript">
// Display random changing images, (c) 2005 Two Brothers Software.
document.write(tbstagline[randomNumber(tbstagline.length - 1)]);
</script>

Feel free to use this script in it's any way you would like as long as you like. Be sure to use whatever ALT tags you would like but make sure that all quotes inside the random tagline ARE single quotes.

This is what this code looks like RANDOM IMAGES PAGE

To create a tagline with a <a href> tag to link to different pages use the following modifications:

tbstagline[0] = "<a href='http://www.websitename1.com'><img src='img1.jpg' alt='' width='wdth' height='hght'></a>";
tbstagline[1] = "<a href='http://www.websitename2.com'><img src='img2.jpg' alt='' width='wdth' height='hght'></a>";
tbstagline[2] = "<a href='http://www.websitename3.com'><img src='img3.jpg' alt='' width='wdth' height='hght'></a>";
tbstagline[3] = "<a href='http://www.websitename4.com'><img src='img4.jpg' alt='' width='wdth' height='hght'></a>";


Having trouble with cut and paste? Download a .zip file of the Random Images Java Script.

You may donate to Two Brothers Software to help support Random Images!

Last Updated ( Saturday, 09 December 2006 )