javascript - Dynamically creation select box options issue in IE8 -
i using following function create add options select box
//add options requested select box addoptionstoselect : function(__enum , obj, selected_value) { $(__enum).each(function(i){ var optn = new option(this.text, this.val) if(selected_value === this.val){ optn.setattribute('selected', 'selected') } $(obj)[0].options.add(optn); }); return obj }
__enum
key value pair containing value , text pass select optionobj
select box obj created dynamicallyselected_value
value needs set selected on select box.
the problem here optn.setattribute('selected', 'selected')
works fine in browsers expect ie8.
i looking workaround allow me set selected value in browsers dynamically.
i'd add option so:
var select = document.getelementbyid("drop-down"); var newoption = document.createelement("option"); newoption.innerhtml = 'hello'; select.appendchild(newoption);
here's example: my fiddle
Comments
Post a Comment