<p>I have the following HTML <code>&lt;select&gt;</code> element:</p>

<pre><code>&lt;select id="leaveCode" name="leaveCode"&gt;
  &lt;option value="10"&gt;Annual Leave&lt;/option&gt;
  &lt;option value="11"&gt;Medical Leave&lt;/option&gt;
  &lt;option value="14"&gt;Long Service&lt;/option&gt;
  &lt;option value="17"&gt;Leave Without Pay&lt;/option&gt;
&lt;/select&gt;
</code></pre>

<p>Using a JavaScript function with the <code>leaveCode</code> number as a parameter, how do I select the appropriate option in the list?</p>

You can use this function:
```
```
function selectElement(id, valueToSelect) {    
    let element = document.getElementById(id);
    element.value = valueToSelect;
}

selectElement('leaveCode', '11');
```
```
```
```
<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>
</select>
```
```
Optionally if you want to trigger onchange event also, you can use :
```
```
element.dispatchEvent(new Event('change'))
```
```