Select a specified value from a combo box
Is it possible to select a specified val开发者_如何学JAVAue from a combo box by clicking on a button.
option 1:
Suppose you want to set value to 3 in your dropdown named 'sel'
<input type="button" value="set to 3" onclick="document.getElementById('sel').value = 3" />
option 2:
If you want to set specific text (say 'myvalue') as selected display text (which already exists in the dropdown list), then you can use loop
for (i=0;i<document.getElementById('sel').length;i++)
{
if ('myvalue' == document.getElementById('sel').options(i).text)
{
document.getElementById('sel').options(i).selected = true;
return;
}
}
精彩评论