html select not show selected even after set selected -
html select not show selected even after set selected -
i have country dropdown , set selected attribute us. can see select="selected" select alternative having value in firebug. neither firefox or chrome shown selected. have code populate & selected country follows.
var countrydata = getcountrydata(); var html = '<option value="">select country</option>'; $.each(countrydata, function(key,value) { if(defaultvalue == value.id) { html = html + '<option value="'+value.id+'" selected="selected">'+value.name+'</option>'; } else { html = html + '<option value="'+value.id+'">'+value.name+'</option>'; } }); countryfield.html(html);
if possible reason browser not shown selected set attribute selected.
update : ok guys, expecting must conflicted other code. , case . using bootstrapvalidator , special phone call "resetform" did behavior. 1 thing did not understand why still html select in firebug shown selected attribute ? @ lastly placed code after resetform call. suggestions & help.
you don't need selected="selected" value.id + ' selected>' + ... should not lastly, check
defaultvalue == value.id
in debugger.
html html-select selectedvalue
Comments
Post a Comment