json - Refresh dropdown with Jquery -
i have 1 dropdown displaying month january current month in jquery mobile. i'm getting data using json. problem selected option not getting refresh.
$.ajax({ type: "post", url: "../modules/loadmonth.php?id=getoption&studid=" + $('#studentids').val(), contenttype: "application/json; charset=utf-8", datatype: "json", success: function (data) { $.each(data, function (i, item) { var sel; if (date[i].optval == date[i].curmon) { sel = "selected"; } else { sel = ""; } result = '<option value=' + data[i].optval + '' + sel + '>' + data[i].opt + '</option>'; }); $('#getmon').append(result); } });
the value
attribute should in quotes, more importantly you'll need space between , selected
attribute.
Comments
Post a Comment