javascript - Find previously selected value of drop down list on change event -
function loaddata(id) { var employeeid = $.trim($("#employeeid").val()); var employeetype = $.trim($("#employeetype").val()); var obj = ""; var cityid = $.trim($("#ddlcity").val()); obj = new viewmodel1(employeeid, employeetype, 0, $.trim($("#deptname").val()), "", "", $.trim($("#sectionname").val()), cityid); var posteddata = json.stringify(obj); loader(); $.ajax({ //........... //........... })
}
i have above function , want selected value in element #ddlcity. above function called line below.
@html.dropdowngrouplistfor(m => m.cityid, model.groupedtypeoptions, new { name = "ddlcity", id = "ddlcityname", @onchange = "javascript:loaddata(this.value)" })
var cityid = $.trim($("#ddlcity").val()); giving me cityid of new selection in dropdownlist.
so how can cityid of selected value?
might post comment answer (too:).
have onchange
store new value data-
attribute/data-storage on select element. can pick in subsequent changes.
e.g. http://jsfiddle.net/trueblueaussie/blc12tu0/
$(".selector").change(function() { // previous value (if any) var prev = $(this).data("prev"); // store new value next time $(this).data("prev",$(this).val()); $('#output').html(prev); }).each(function(){ // save initial dropdown value previous value (for each select) $(this).data("prev", $(this).val()); });
Comments
Post a Comment