Reputation: 21
I am using a amultiple dropdown with check boxes in my web page. For the check box inside the multiselect dropdown I have used "multiple-select.js" plugin from http://wenzhixin.net.cn/p/multiple-select/ Whenever after submitting value I try to clear the value from the dropdown , it is not happening i.e. the value is not disappearing. Please suggest if any other ways to do. Here my code snippet below: (If any more information needed please reply)
CSHTML code:
<div class="col-md-2">
<div>
@Html.Label("Genset")
</div>
<div>
@Html.DropDownListFor(model => model.Environment, new List<SelectListItem>
{
new SelectListItem() {Text = "ONT", Value = "ONT"},
new SelectListItem() {Text = "TST", Value = "TST"},
new SelectListItem() {Text = "ACC", Value = "ACC"},
new SelectListItem() {Text = "PrePROD", Value = "PrePROD"},
new SelectListItem() {Text = "PROD", Value = "PROD"}
}, new { @class = "Multiple", multiple = "multiple", style = "width: 126.989px; padding-bottom: 70px;", @id = "ddlEnvironment" })
</div>
</div>
Javascript :
$('#btnSubmit').click(function(){
var env = $('#ddlEnvironment').val();
if ( env == null)
{
//error popup
}
else
{
// submit operation using ajax call
//I have tried below options, nothing is working
$('#ddlEnvironment').attr('value', null);
or
$('#ddlEnvironment').val(null);
or
$('#ddlEnvironment').val('');
}
});
Upvotes: 0
Views: 9466
Reputation: 18997
By using the below code you can uncheck all the values.
$('#ddlEnvironment').multipleSelect('uncheckAll');
Also you can refresh the plugin
$('#ddlEnvironment').multipleSelect('refresh');
Taken from the Plugin Documentation (navigate to the Methods section)
Upvotes: 1