开发者

Dynamically adding options to drop down box

开发者 https://www.devze.com 2023-02-03 07:38 出处:网络
I have a drop down box in which values are entered dynamically. But sometimes it\'s value does not get refreshed. How can I force the drop down box to refresh?

I have a drop down box in which values are entered dynamically. But sometimes it's value does not get refreshed. How can I force the drop down box to refresh?

var DropdownBox =document.getElementById("xyz")开发者_运维百科;
var optn = document.createElement("OPTION");
optn.text="txt";
optn.value="val";
DropdownBox.options.add(optn);


That should be DropdownBox.add(optn);, I believe. See the MDC page describing HTMLSelectElement.


Have you tried

DropdownBox.appendChild(optn);

?

Afaik options.add() is only supported in IE.


This is what I use:

var target=document.getElementById('myselect');    
var optionName = new Option('option text', 'option value');    
var targetlength = target.length;    
target.options[targetlength] = optionName; 
0

精彩评论

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