doutao4938 2019-07-27 05:18
浏览 110
已采纳

如何清空ajax调用onchange中的选择框使用jquery的多选插件更改另一个选择框?

I am having 2 dependent dropdowns. Second one is depend on first dropdown. I am using onchange event to get data in second dropdown with ajax call.

below is my 2 dropdowns and ajax call :

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 :

 $(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.

  • 写回答

1条回答 默认 最新

  • 普通网友 2019-07-27 05:35
    关注

    Use reload method to display the new options after populating.

    $('#CompanyName').multiSelect('reload');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换