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 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据