Categories:

Accessing the select element of a form

In this tutorial, we look at using JavaScript to access the select element. See how to accomplish tasks such as finding out which option was selected and creating a drop down navigational menu.

Working with selection boxes

Selection lists are quite commonly used in forms-with some help from JavaScript, it can be very useful sometimes.

Example of selection list:

The fundamental way to access forms is through its name. Accessing selection lists are no different. Here's an example:

<form name="George">
<p><select name="example" size="1">
<option>choice1</option>
<option>choice2</option>
<option>choice3</option>
<option>choice4</option>
</select></p>
</form>

To access anything within this selection list, we would write:

document.George.example

Accessing selection lists in JavaScript can be quite confusing. Where's the confusion, you ask? Well, the above line will access only the selection list itself, and not the individual elements. We have to go deeper to do that. Lets discuss how this is done.