I am using the following function to create a add options to my select box
//add options to the 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
is the key value pair containing the value and the text that we pass to the select optionobj
is the select box obj which is also created dynamicallyselected_value
is the value that needs to set as selected on the select box.
The problem here is optn.setAttribute('selected', 'selected')
works fine in all the browsers expect IE8.
I am looking for a workaround that will allow me to set the selected value in all the browsers dynamically.