jquery - dynamically populated select does not let to select the options -


i dynamically populate select using jquery $ajax when select value, reloads again, looks keeps re-populating whenever click, options gets selected when add "alert(this.value)". can me understand missing?

added snippet of code here :

.... $("select#tassigned").change(function(){ $("select#tassigned option[value=28]").prop("selected", true).end().change();       }); ....       $.ajax({         type: "post",         url: profilesaction ,     async: false,         datatype: "json",         data: {'select' : 1 },     success: function(request) {       $("select#tassigned").html("<option></option>");                  $.each(eval(request), function(i,item){         $("select#tassigned").append("<option value="+item.cid+">"+ item.second + " - " + item.third +"</option>");         });       }     });              html code:       <select name='tassigned' class='form-control' id='tassigned'>   <option>1   <option>2   </select> 

in above example, hardcoded value=28 see if gets selected did n't.

$.ajax populates select options onclick of tab href(not shown here part of code works great), when proceed select option reloads again though see gets selected when "alert" it. want value shown "selected" rather values getting repopulated again.

i went through several questions in nothing helped. tried prop instead of attr did not either.

i'm using 1.9, tested firefox , safari, did not work either of attr or prop.

generally how done , can give me sample ? help.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -