douchengchu8374 2013-09-24 20:13
浏览 32
已采纳

如何从两个下拉列表中获取价值并将其传递给不同的网址?

I have two dropdown and want to get the selected year value of the first one and add it to the url of the header page and also to the second dropdown url options so that when I select a php page from the second dropdown I can see the year value on the page.

<?php    $id = $_GET['id']; ?>

   <form method="post">
    Report Period:
    <select name="year" id="year"  >
        <option style="display:none;"> Select</option>

        <?php

        $result1 = mysql_query("select year from year_data where id=$id");

        while ($row = mysql_fetch_assoc($result1)) {

            $period= $row['year'];


            echo "<option  value=\"$period\">$period</option>";

        }
        ?>

    </select>

     Type:
    <select name="report"  id="report" > 


    <option style="display:none;">--Select--</option>


        <?php

    echo "<option value=\"".reportA.".php?org_id={$id}&year=\">reportA</option>";
 echo "<option value=\"" . reportB . ".php?org_id={$id}&year=\">report B</option>";

        ?>

    </select>
    <input type=submit name=button method="post"  onClick="getValues()"  value="view" >

</form>
    <SCRIPT language="JavaScript">

    function getValues() {
var year = document.getElementById("year").value;
var report=document.getElementById("report").value;
    window.location.href = 'header.php?year=' +  year.options[year.selectedIndex].value
    window.location.href = report +  year.options[year.selectedIndex].value


       }


    </SCRIPT>
  • 写回答

2条回答 默认 最新

  • dongpiao9078 2013-09-24 20:36
    关注

    window.location.href call will immediately redirect you referenced page. So 2nd call will not work.

    What you need to do is ,

    Lets say you have two page page1.php <- say this has the code you have written in the question.

    page2.php <- You can get values from the get vars. (See Below )

    In page1.php change this two line

    window.location.href = 'header.php?year=' + year.options[year.selectedIndex].value

    window.location.href = report + year.options[year.selectedIndex].value

    To

    yearValue = year.options[year.selectedIndex].value;

    reportValue = report.options[report.selectedIndex].value;

    window.location.href = 'page2.php?year=yearValue&report=reportValue';

    In page2

    report = $_GET['report']

    year = $_GET['year']

    Happy Coding...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

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