brass-kazoo brass-kazoo - 1 year ago 49
HTML Question

How do I programatically 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?

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