Retrieving data from selection lists

This script shows how to use the Select object to determine which selection has been made. The analysis is done in two steps:
  1. determine the index of the selected item
  2. determine the selection option by using the index

Select a color

HTML
<form name="colorSel" action="#">
<select name="sList" onchange="selColor()">
  <option> ??? </option>
  <option> blue </option>
  <option> green </option>
  <option> red </option>
  <option> yellow </option>
  <option> black </option>
</select>
</form>

JavaScript
<script type="text/javascript">
function selColor()
{
  var index = document.colorSel.sList.selectedIndex;
  var color = document.colorSel.sList.options[index].text;
  alert("Selected color is: " + color);
}
</script>