Click to See Complete Forum and Search --> : random selection


Bob Spaulding
08-17-2003, 07:16 AM
I need a simple piece of code to randomly open 1 of 5 html pages each time a user selects a menu item. Can you assist?

Charles
08-17-2003, 07:23 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<script type="text/javascript">
<!--
Aarray.prototype.random = function () {return this[Math.floor(Math.random() * this.length)]}
// -->

url = ['fee.html', 'fie.html', 'foe.html', 'fum.html', 'foo.html'];
</script>
<ul>
<li><a href="fee.html" onclick="this.href = url.random()">One</a></li>
<li><a href="fie.html" onclick="this.href = url.random()">Two</a></li>
<li><a href="foe.html" onclick="this.href = url.random()">Three</a></li>
<li><a href="fum.html" onclick="this.href = url.random()">Four</a></li>
<li><a href="foo.html" onclick="this.href = url.random()">Five</a></li>
</ul>