2

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);
suspectus
  • 16,548
  • 8
  • 49
  • 57
akshay
  • 755
  • 5
  • 16
  • 22

3 Answers3

1

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

lonesomeday
  • 233,373
  • 50
  • 316
  • 318
0

Have you tried

DropdownBox.appendChild(optn);

?

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

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
0

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; 
derekcohen
  • 1,514
  • 4
  • 17
  • 34