Random tip / info-box with javascript array

Submitted by n8coder on Mon, 04/27/2009 - 14:22
<p id="cw_js_random_tips">This is reserved-place for a random tip.
Put it somewhere on your website.
In this example p must be placed above javascript-code.</p>

<script language="javascript">

var myarray=new Array();

myarray[0] = "The content of first index ";
myarray[1] = "Something for second index ";
myarray[2] = "Something for third index ";
// ...

var randNr = Math.floor(Math.random()*myarray.length);

// alert(myarray[randNr]);
// use advanced javascript to display content somewhere on your page

document.getElementById('cw_js_random_tips').innerHTML = myarray[randNr];


Add new comment