jeudi 26 mars 2015

How to clear dropdown options value?


Recently i am facing an unknown problems. I am using customized dropdown list in MVC4 and populating data by ajax. It is working fine but problem is, it is not clearing data after successfully sending data to the controller. Here i tried the example..



<select data-placeholder="Select a Brand..." style="width:254px;" name="brand" id="brand">
<option value=""></option>
</select>

$("#brand").select2({
width: 254
});


For clearing drop down list i have tried like this..



$("#brand").val("");


I have search many example refreshing data in drop down list but i failed. Please help me to solve the problem. Here i have shared my long code



<script type="text/javascript">
$(document).ready(function () {

$("#brand").select2({
width: 254
});
$.get('/Settings/Brands/', function (data) {
$.each(data, function (index, c) {
$('#brand').append('<option value="' + c.id + '">' + c.name + '</option>');
});
});


$('#btnAdd').live("click", function () {
if (confirm("Do you want to Save?") == true) {
$.ajax({
cache: false,
async: false,
type: "POST",
url: "/Settings/ItemAdd/",
dataType: "json",
data: adata,
success: function (data) {
alert(data.msg);
$('#list').trigger('reloadGrid');
},
error: function (data) {
alert(data.msg);
$('#list').trigger('reloadGrid');
}
});
}
$("#itemname").val("");
$("#batchNo").val("");
$("#desp").val("");

$("#brand").find("option").val("");
$("#ctg").val("");
$("#supplier").val("");
$("#unittype").val("");
$("#qty").val("");
$("#bprice").val("");
$("#sprice").val("");
$("#Edate").val("");
$("#qlimit").val("");
$("#vat").val("");
$("#icode").val("");
});





});
</script>




Aucun commentaire:

Enregistrer un commentaire