我有兩個下拉菜單,並希望獲得第一個選定的年份值,並將其添加到頁眉的網址以及第二個下拉網址選項,以便當我從第二個下拉菜單中選擇一個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>
爲什麼不提交表單? –
將表單的動作設置爲下一頁,然後您可以使用'$ _POST'從下一頁訪問表單值。 – Jasper
你沒問題在答案中使用jQuery? – gibberish