Array in selection drop down list

Hello, I hope that someone would be able to help me to solve this simple problem.

My goal is to get the value in the array from selection drop down list.

Basically, I create an Array in Javascript and a selection drop down list in the body.


<script type="text/javascript">
var even = new Array(2, 4, 6);
</script>
.
.
.
<select id="evenNumbers">
     <option value="1">two</option>
     <option value="2">four</option>
     <option value="3">six</option>
</select>

My question is how can I get the value in the Array if I select the option from the drop down list? e.g. when I select “two” from the drop down list, but I can get the value of “2” in the array in order to do some calculation.

Thanks.

if I understand correctly, you want to check if the selected value in the <select> is in the array called even.

if that is so, one way is to

  1. put an onchange event handler on the <select> which calls a function.

  2. that function then takes the selected value and loops through the even array.

  3. at each iteration through the loop, check the value of the current array element against the selected option value.

  4. if they match, then do the required processing