dreamer2014520 2015-03-31 20:17 采纳率: 0%
浏览 148

使用ajax将选定下拉列表的值作为参数传递给另一个下拉列表中的函数

I need some advice with an ajax function I am building and haven't been able to figure it out so far. So I have select order_by dropdown which uses ajax function called searchFilter to change this.value which is a variable called $orderr_by:

<select name="order_by" 
        onchange="searchFilter('0',
                               '<?php echo $maxRows;?>',
                               this.value);">

I have another select condition dropdown that calls the same searchFilter function and should get the new $orderr_by argument, when the onchange event is triggered for order_by dropdown.

Below I have got it to work for three static arguments but I need to make it work when the $orderr_by argument is changed:

<select name="condition" id="condition" 
        onchange="searchFilter('<?php echo $pageNum;?>',
                               '<?php echo $maxRows;?>',
                               '<?php echo $orderr_by; ?>');">

My Axaj looks like this:

function searchFilter(pageNumbr,maxRows,order_by) {

    var filter  = jQuery.noConflict();

    filter.post(
        MYSURL+'ajaxphp/searchFilters.php?page_no='+pageNumbr+'&max_rows='+maxRows+'&order_by='+order_by, 
        filter('#filterFrm').serialize(), 

        function(html){  
            arrHtml = html.split('<####>');
            filter('#resultContainer').html(arrHtml[0]);    
        }
    );

    } // function searchFilter()
  • 写回答

1条回答 默认 最新

  • douleijiang8111 2015-03-31 20:30
    关注

    Select the value of the [name=order_by] element.

    In pure JS you do this as follows:

    var element = document.getElementById("order_by");
    var order_by = element.options[element.selectedIndex].value;
    

    jQuery has cleaner ways of doing this.

    You do not need order_by in your function declaration. If you do for some reason need to pass order_by from other code, you have to make sure order_by is not already defined:

    if (order_by === undefined) {
       ...
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥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#的问题,如何解决?