Categories
forms html html-table php

Cannot pass contents of html table as form data on a POST?

I have a table, code as follow,
the table have select and checkbox, I try to wrap my table in a form and post to results.php to echo,
but when submit the form, it’s not working. How to get the checkbox checked value from 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">&nbsp;</td>
<td width="30">&nbsp;</td>
<td width="30">&nbsp;</td>
<td width="30">&nbsp;</td>
<td width="38">&nbsp;</td>
<td width="25">&nbsp;</td>
<td width="114">&nbsp;</td>
<td width="456">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Range</td>
<td>&nbsp;</td>
<td><p>
<input type="checkbox" name="absolute" onChange="change(this)" onclick="show(this,'s1');">
Absolute</p>
<p>&nbsp;</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>&nbsp;</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>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Location</td>
<td>&nbsp;</td>
<td colspan="2">
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Index</td>
<td>&nbsp;</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>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Keyword</td>
<td>&nbsp;</td>
<td colspan="2">
<input type="text" name="keyword" id="keyword" width="200">
</span></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</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 "];
?>

To retreive a value from POST request using PHP you can use something like this

$checkbox = $_POST['absolute'];

The parameter name and the value is the same as on your html tag.

Eg:

<input name="absolute" type="checkbox" value="Your value" />