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   } 
  1. __enum key value pair containing value , text pass select option

  2. obj select box obj created dynamically

  3. selected_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

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -