[英]How to empty select box in ajax call onchange another select box with multiselect plugin of jquery?
I am having 2 dependent dropdowns.
我有2个依赖下拉列表。 Second one is depend on first dropdown.
第二个取决于第一个下拉菜单。 I am using onchange event to get data in second dropdown with ajax call.
我正在使用onchange事件来通过ajax调用在第二个下拉列表中获取数据。
below is my 2 dropdowns and ajax call : 以下是我的2个下拉菜单和ajax调用:
first select box: 首先选择框:
<select name="cust_type" id="cust_type" class="cust_type"
onchange="getCustomersByType(this.value);" >
<?php echo $customer_type;?>
</select>
Second select box: 第二选择框:
<select name="CompanyName[]" id="CompanyName" multiple class="customer_name" >
</select>
ajax call : 阿贾克斯电话:
function getCustomersByType(value)
{
var getCust = $('#cust_type').val();
var customer_type = value;
$.ajax({
method: "GET",
dataType: 'json',
url:"include/ajax_files/bank_book/getdata.php?getCust="+getCust,
success:function(data)
{
$('#CompanyName').empty();
$.each(data, function(index, value)
{
$("#CompanyName").append('<option value="' + value.CUSTOMER_ID + '"' +
'>' + value.CUSTOMER_NAME+ '</option>');
$('#CompanyName').multiselect('rebuild');
});
}
});
};
my data is proper. 我的数据是正确的。 I am able to change my second dropdown with change on first.
我可以先更改第二个下拉菜单。 But when i am using multiselect plugin with checkbox for multiselect second dropdown failed to change data.
但是,当我使用带复选框的多选插件时,多选第二个下拉菜单无法更改数据。
Below is code for multiselect : 下面是multiselect的代码:
$(document).ready(function(){
$('#CompanyName').multiselect({
columns: 1,
placeholder: 'Select Com',
search: true,
selectGroup: true,
selectAll: true,
maxPlaceholderOpts: 0,
});
});
please help me with this to empty select onchange first dropdown and show data. 请帮我解决这个问题,以清空选择onchange的第一个下拉列表并显示数据。
填充后,使用reload
方法显示新选项。
$('#CompanyName').multiSelect('reload');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.