Introduction To Javascript
Using List Boxes

HTML

<form name="myForm">
<select name="myDrop">
<option SELECTED value="http://www.google.co.uk/">Google</option>
<option value= "http://lycos.co.uk/">Lycos</option>
</select>
<input type="button" onclick="loader()" value="Click">
</form>

The value settings for each of the option tags will be used by the function which loads the page. The word SELECTED in the first option ensures that the specified option is selected on loading the page.

Javascript in <head>

<script type="text/javascript">
function loader() {
var whichone = document.myForm.myDrop.selectedIndex
var whoami = document.myForm.myDrop.options[whichone].value
self.location =whoami
}
</script>

In line 3 the script checks which of the options has been selected. Line 4 looks for the value of the selected option. Line 5 changes the location value (web address) of the current page to this value, effectively linking to the chosen web page.

Exercise 13

Think how much nicer the quiz you made would be if it were multiple choice. Change the format of the quiz so that users can select from at least 3 possible answers.