我有一张表,代码如下, 该表有select和checkbox,我尝试将表包装在一个表单中并发布到results.php以回显, 但是在提交表格时,它不起作用。如何从results.php获取复选框选中的值?
<script>
var currentSelected = "";
var currentItem = "";
function show(obj, item) {
if (currentSelected != "" && currentSelected != obj) {
currentSelected.checked = false;
document.getElementById(currentItem).style.display = currentSelected.checked ? "block" : "none";
}
document.getElementById(item).style.display = obj.checked ? "block" :"none";
currentSelected = obj;
currentItem = item;
}
</script>
<form action="results.php" method="post">
<table width="805" border="0" >
<tr>
<td width="30"> </td>
<td width="30"> </td>
<td width="30"> </td>
<td width="30"> </td>
<td width="38"> </td>
<td width="25"> </td>
<td width="114"> </td>
<td width="456"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>Range</td>
<td> </td>
<td><p>
<input type="checkbox" name="absolute" onChange="change(this)" onclick="show(this,'s1');">
Absolute</p>
<p> </p>
<p>
<input type="checkbox" name="quick" onChange="change(this)" onclick="show(this,'s2');">
Quick</p></td>
<td><p>
<div id="s1" style="display:none">
<input class="date" id="datepicker" type="text" value="" name="from" placeholder="From" onFocus="this.value = '';" onBlur="if (this.value == '') {this.value = '';}" required=>
<input class="date" id="datepicker1" type="text" value="" name="to" placeholder="To" onFocus="this.value = '';" onBlur="if (this.value == '') {this.value = '';}" required=>
</div>
</p>
<p> </p>
<p>
<div id="s2" style="display:none">
<select name="quickselect" id="quickselect" >
<option value="30">Last 30 minutes</option>
<option value="60">Last 1 hour</option>
<option value="4h">Last 4 hour</option>
</select>
</div>
</p></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>Location</td>
<td> </td>
<td colspan="2">
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>Index</td>
<td> </td>
<td colspan="2"><select name="loc" id="locselect" >
<option value="la">LA</option>
<option value="ny">NY</option>
<option value="all">CA & NY </option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>Keyword</td>
<td> </td>
<td colspan="2">
<input type="text" name="keyword" id="keyword" width="200">
</span></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td colspan="3"><div class="bnr-btn">
<input type="submit" value="Search">
</div></td>
</tr>
</table>
</form>
results.php
<?php
//how to echo the checkbox value ?????????
$quickselect= $_POST["quickselect"];
$locselect =$_POST["locselect "];
$keyword = $_POST["keyword "];
?>
答案 0 :(得分:0)
要使用PHP从POST请求中检索值,您可以使用类似这样的内容
$checkbox = $_POST['absolute'];
参数名称和值与html标签上的相同。
例如:
<input name="absolute" type="checkbox" value="Your value" />
答案 1 :(得分:0)
表示复选框:
$checkbox1=$_POST['absolute'];
$checkbox2=$_POST['quick'];
获取日期值
$from=$_POST['from'];
$to=$_POST['to'];