dongxingchang9345 2013-10-29 07:36
浏览 15

onboot事件,用于下载bootstrap multiselect

i have one div for duel multiselect of provinces list which when i click on every option it is moved to another box(user can select several provinces). and another div for duel multiselect of districts.

    <div>
        <select multiple class="multiselect" id="province" name="province">  
            <?PHP foreach($provinces->result() as $province){ ?>
                 <option value="<?=$province->id?>"><?=$province->name?></option>
            <?PHP } ?>  
       </select> 
    </div>
    <div id="district_div">
        <select multiple class="multiselect" id="district" name="district" >  
        </select>
    </div>  

the list of province is correct and user can select multi provinces. but what i need is an onchange in province select tag to bring the districts of selected province and put them in district_div. i have the ajax for onchange to bring the districts:

    function bring_page(page,name,id,divname,str)
{
     var dropdownIndex = document.getElementById(name).selectedIndex;
     var dropdownValue = document.getElementById(name)[dropdownIndex].value;
     var url=page;
     var params='&'+id+'='+dropdownValue+'&'+str;

     //call ajax 
     makerequest_sp(url, params, divname);
}

the function bring_page is correct and work for normal select. i think the problem is with bootstrap. i am using plugins of bootstrap.

thanks for help

  • 写回答

1条回答 默认 最新

  • douyinglan2599 2013-10-29 07:54
    关注

    You need to get the values of the options in a loop because you will have multiple. I don't know how your backend is expecting the data, but something like this could work.

    function bring_page(page, name, id, divname, str) {
         var url=page;
         var params = "&" + id +"=";
    
         var dropdown = document.getElementById(name);
         var options  = dropdown.options;
         var values = [];
         for (var i = 0; i < options.length; i++) {
            if (options[i].selected) {
                values.push(options[i].value);
            }
         }
    
         params += values.join(",");
    
    
         //call ajax 
         makerequest_sp(url, params, divname);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?