我有一个带有按钮的页面,可以打开一个弹出窗口。此弹出窗口有两个复选框。如果选中复选框1,它应该重定向到page1.php,如果选中复选框2,它应该重定向到page2.php,如果两个复选框都被选中,它应该重定向到page3.php。我已经在javascript和php中实现了这个脚本。
弹出窗口脚本如下:
<html>
<head>
<script language="Javascript">
function redirectTo(){
window.opener.location.href="grabvalues.php";
self.close();
}
</script>
<style>
#checkboxes,
#submit-button{
display:none;
}
</style>
<script language="JavaScript">
function rework(){
document.getElementById("checkboxes").style.display = "block"
document.getElementById("submit-button").style.display = "block"
document.getElementById("rework-button").style.display = "none"
}
</script>
</head>
<body>
<form method="POST">
<input type="button" id="rework-button" value="Rework" onclick="rework()"/>
<div id="checkboxes">
Tech & Price: <input type="checkbox" id="techprice" name="techprice" value="techprice" />
Terms & Conditions: <input type="checkbox" id="terms" name="terms" value="terms" />
</div>
<input type="submit" id="submit-button" value="Proceed" OnClick="redirectTo()"/>
</form>
</body>
</html>
grabvalues.php脚本如下。我有这个PHP脚本的问题
<?php
$techprice = $_POST['techprice'];
$terms = $_POST['terms'];
if ($techprice=1) {
Redirect('page1.php', true);
}
if ($terms=1) {
Redirect('page2.php', true);
}
if ($techprice=1 && $terms=1) {
Redirect('page3.php', true);
}
?>
答案 0 :(得分:0)
使用此:
$techprice = $_POST['techprice'];
$terms = $_POST['terms'];
if ($techprice ==1 && $terms==1) {
Redirect('page3.php', true);
}
elseif ($techprice==1) {
Redirect('page1.php', true);
}
elseif ($terms==1) {
Redirect('page2.php', true);
}
else
{
// do nothing
}
答案 1 :(得分:0)
首先,您需要将值提交给PHP
window.opener.location.href = "grabvalues.php?techprice=" + (techprice.checked ? 1 : 0) + '&terms=' + (terms.checked ? 1 : 0);
然后你的PHP代码应该像
一样改变 <?php
$techprice = $_GET['techprice'];
$terms = $_GET['terms'];
if ($techprice=1 && $terms=1) {
Redirect('page3.php', true);
} elseif ($techprice=1) {
Redirect('page1.php', true);
} elseif ($terms=1) {
Redirect('page2.php', true);
}
?>