brass-kazoo brass-kazoo - 4 months ago 22
Javascript Question

How do I programmatically set the value of a select box element using javascript?

I have the following HTML select element:

<select id="leaveCode" name="leaveCode">
<option value="10">Annual Leave</option>
<option value="11">Medical Leave</option>
<option value="14">Long Service</option>
<option value="17">Leave Without Pay</option>

Using a javascript function with the
number as a parameter, how do I select the appropriate option in the list?

function SelectElement(valueToSelect)
    var element = document.getElementById('leaveCode');
    element.value = valueToSelect;