开发者

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;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜