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


Bob Spaulding
08-18-2003, 06:29 AM
HELP!~

Still need help with code that will randomly select 1 of 5 html pages each time the page upon which the code is written is accessed.

The selected file name needs to be assigned to a variable which would appear in a menu (within a frame on the page).

Upon selection of the item in the menu, the randomly selected file would then be opened in another frame on the same page.

I am 62 years of age and pretty much a beginner with script languages so please be kind and insert comments so I can understand what is happening.

Bless you, my son, your name should be placed in lights!

pyro
08-18-2003, 07:49 AM
Building off my prior example in the DHTML forums:

<form action="">
<select name="myselect" onchange="window.location.href=this.options[this.selectedIndex].value">
<option value="">Go to URL:</option>
<script type="text/javascript">
array = new Array("http://www.infinitypages.com","http://www.webdevfaqs.com","http://www.w3c.org","http://www.php.net","http://www.forums.webdeveloper.com")
num = Math.round(Math.random()*4);
document.write('<option value="'+array[num]+'">'+array[num]+'</option>');
</script>
</select>
</form>Note that the menu will only work for those with JavaScript enabled.