[英]How to get value from two dropdown and pass it to different url?
我有两个下拉菜单,想要获取第一个下拉菜单的选定年份值,并将其添加到标题页的网址以及第二个下拉菜单网址选项中,以便当我从第二个下拉菜单中选择一个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>
window.location.href调用将立即重定向您引用的页面。 因此,第二通电话将无法使用。
您需要做的是,
假设您有两个页面page1.php <-说这具有您在问题中编写的代码。
page2.php <-您可以从get vars获取值。 (见下文 )
在page1.php中更改这两行
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']
快乐编码...
您在寻找这样的东西吗?
如果我正确理解了您的需要,则无需更改您的getValues()fn,因为这些值没有更改-仅是第二选择的可见部分。
这个对吗?
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.