I want to select a value in a select/option dropdown using javascript only.
Revised sorry for confusion. Here is revised code.
document.getElementById("sel_activity").value = activity;
This will also work, but is a bit longer..
<select id='sel_activity'>
<option value='CYC'>Cycle Count</option>
<option value='INV'>Inventory Count</option>
<option value='INVDROP'>Inventory Drop off</option>
<option value='INVPICK'>Inventory Pick up</option>
<option value='TRAIN'>Training</option>
</select>
<script type="text/javascript">
var select = 'CYC';
var myselect=document.getElementById("sel_activity")
for (var i=0; i<myselect.options.length; i++){
if (myselect.options[i].value == select)
{
myselect.options[i].selected = true;
}
else
{
myselect.options[i].selected = false;
}
}
</script>