douran9707 2011-08-11 01:37
浏览 42

获得两个下拉值

i was just wondering if i could get the values of two different drop downs then pass it on jquery to back to php?

you see i have these two drop downs. one for the month and one for the year.the user could choose which month and year she/he would like then the display on the graph would change depending on the month and year chosen.i was able to do it for a single drop down but i can't do it on two drop downs.

    <script type="text/javascript">
      $(document).ready(function()
   {
     $("#months").change(function(event)
    {
         var m=$(this).val();
         if( m == '00')
         { 
         }
         else if(m!='00' || m!='NULL')
         {
            $("#display").load('../crd_reports/month.php', {"m":m});
         }

    });

    $("#years").change(function(event)
    {
         var y=$(this).val();
         if( y == '10')
         {
         }
         else if(y!='10' || y!='NULL')
         {
            $("#display").load('../crd_reports/month.php', {"y":y});
         }
    });
  });
    </script>   

    <div>
  <select id="months">
    <option value='00'>Month...</option>
            <option value='01'>Jan</option>
            <option value='02'>Feb</option>
            <option value='03'>Mar</option>
            <option value='04'>Apr</option>
            <option value='05'>May</option>
            <option value='06'>June</option>
            <option value='07'>July</option>
            <option value='08'>Aug</option>
            <option value='09'>Sept</option>
            <option value='10'>Oct</option>
            <option value='11'>Nov</option>
            <option value='12'>Dec</option>
      </select>
     <select id="years">
       <?php
          for($yr=10; $yr<=$year; $yr++)
    {
        echo "<option value='".$yr."'>".$years[$yr]."</option>";
    }
   ?>
    </select>
  </div>

this is the start of my month.php

     <?php
      if (isset($_REQUEST['m'])) 
      {
      $m = $_REQUEST['m'];
     // $y = $_REQUEST['y'];
      include '../../include/dbconnect.php';

      ?>
  • 写回答

2条回答 默认 最新

  • duanmu6752 2011-08-11 01:41
    关注

    You can create a function that runs on change of either dropdown, and passes in both parameters at once:

    $('#months, #years').change(function(event)
    {
        var m=$('#months').val();
        var y=$('#years').val();
    
        // combine the conditions, so both must be valid before running
        if( (m!='00' || m!='NULL') &&
            (y!='10' || y!='NULL') )
        {
            $('#display').load('../crd_reports/month.php', {"y": y, "m": m});
                                         // notice additional param ^^^^^^
        }
    }
    

    Then in month.php, you can grab both parameters and use them to populate your report:

    <?php
    // 'y' also has to be given before we continue
    if ( isset($_REQUEST['m']) && isset($_REQUEST['y']) ) 
    {
        $m = $_REQUEST['m'];
        $y = $_REQUEST['y'];
        include '../../include/dbconnect.php';
    
        // do something with $m and $y
    }
    else
    {
        echo 'Please provide month and year.';
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本