根据从弹出窗口中选择的复选框,重定向
As per checkbox selected from a popup window, redirection
我有一个页面的按钮,打开一个弹出窗口。这个弹出窗口有两个复选框。如果选中复选框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);
}
?>
首先需要将值提交给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);
}
?>
使用
$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
}
相关文章:
- 如何创建只允许用户在选中前一个复选框的情况下选择复选框的复选框验证
- 禁用选择/复选框 当选择/选中另一个时
- 如何使用JQuery按值选择复选框
- jquery选择复选框选择的值
- 取消选中时选择最接近的“从中选择”复选框
- 根据动态值选择和取消选择复选框
- 选择/取消选择复选框,该复选框未按预期使用.coneast('table').find('tbo
- 背景图像切换和隐藏选择复选框
- 如何通过选择复选框和下拉列表用Javascript更改标签值
- 选择复选框的Javascript
- 如何将选择复选框值动态传递给 ajax 调用变量动态发布到 php 变量
- 获取多个选择复选框的值 Javascript
- 翡翠,如果其他速记选择复选框
- jQuery动态选择复选框组onChange
- 按住Shift键并单击以选择复选框范围
- 选中p中的所有复选框:选择复选框菜单
- 选择复选框时显示数据
- 从多个JSON文件中选择复选框时切换标记
- 如何为第一次选择和第二次选择复选框应用不同的颜色
- 如何在HTML中选择复选框时创建弹出窗口