0

2 つのドロップダウンがあり、最初の選択した年の値を取得し、それをヘッダー ページの URL と 2 番目のドロップダウン URL オプションに追加して、2 番目のドロップダウンから php ページを選択すると、ページの年の値。

<?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>
4

2 に答える 2

1

window.location.hrefを呼び出すと、参照ページがすぐにリダイレクトされます。したがって、2 番目の呼び出しは機能しません。

あなたがする必要があるのは、

2 つのページ page1.php があるとしましょう <- これには、質問で記述したコードがあるとします。

page2.php <- get vars から値を取得できます。(下記参照 )

page1.php で、この 2 行を変更します

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

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

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

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

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

ページ 2 で

report = $_GET['report']

year = $_GET['year']

ハッピーコーディング...

于 2013-09-24T20:36:08.943 に答える
0

このようなものを探していましたか?

必要なものを正しく理解していれば、getValues() fn を変更する必要はありません。これらの値は変更されていないためです。2 番目の選択の表示部分のみです。

これは正しいです?

jsFiddle here

var yr;

$(document).ready(function() {
    $('#selone').change(function() {
        yr = $(this).val();
        var txt;
        $('#seltwo option').each(function() {
            txt = $(this).text();
            $(this).text(txt + ' - ' + yr);
        });
    });

}); //END document.ready
于 2013-09-24T20:38:20.467 に答える