Here is my solution to remove the previous append value to the dropdownlist.
<script type="text/javascript">
$(document).ready(function () {
var counter1 = 0;
$("#dropdownCountry").change(function (e) {
var obj1 = { Country: $("#dropdownCountry").val() };
var isRemove1 = false;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://localhost:3323/AjaxWebService.asmx/getState",
data: JSON.stringify(obj1),
dataType: "json",
success: function (data1) {
var appenddata1 = "";
var jsonData1 = JSON.parse(data1.d);
if (counter1 == 0)
counter1 = jsonData1.length;
else {
isRemove1 = true;
}
for (var i = 0; i < jsonData1.length; i++) {
appenddata1 += "<option id=\"appendDataTemp1\" value = '" + jsonData1[i].SHORT_NAME + " '>" + jsonData1[i].FULL_NAME + " </option>";
}
if (isRemove1) {
for (var j = 0; j < counter1; j++) {
$("#appendDataTemp1").remove();
}
counter1 = jsonData1.length; isRemove1 = false;
}
$("#dropdownState").append(appenddata1);
}
});
});
});
</script>
Note : please refer my previous post here to append dropdownlist value
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
0 comments:
Post a Comment