PDA

View Full Version : Passing checkbox variables(total price) to next page



jamrobot
Feb 15th, 2010, 10:25 PM
How would I do this, I have index.html and checkout.html, i need to add up the total price of checked items and pass that number to the next page


index.html


<div id="content">
<h5>&nbsp;</h5>
<table border="7" cellpadding="10" align="center">
<tr>
<td><img src="../book1.jpg" border="0"></td>
<td>Description of product will be here</td>
<td>&nbsp;&nbsp;&nbsp;5</td>
<td>&nbsp;&nbsp;&nbsp;<input name="Buy" type="checkbox" value="5.00" />&nbsp;&nbsp;</td>
</tr>
<tr>
<td><img src="../book2.jpg" border="0"></td>
<td>Description of product will be here</td>
<td>&nbsp;&nbsp;&nbsp;4.50&nbsp;&nbsp;</td>
<td>&nbsp;&nbsp;&nbsp;<input name="Buy" type="checkbox" value="4.50" />&nbsp;&nbsp;</td>
</tr>
</table>

<p>
<br />
<br />

<p>

<form name="loginform" method="post" action="checkout.html">
<input type="submit" value="Checkout">

</form>
</p>
</div>


checkout.html


Price =

Jazzo
Feb 16th, 2010, 07:40 PM
First off, you need to have your table inside the form so that the inputs are accessible, and give your inputs unique names. Also, change your file extensions to .php Try this:
index.php


<form name="loginform" method="post" action="checkout.php">
<div id="content">
<h5>&nbsp;</h5>
<table border="7" cellpadding="10" align="center">
<tr>
<td><img src="../book1.jpg" border="0"></td>
<td>Description of product will be here</td>
<td>&nbsp;&nbsp;&nbsp;5</td>
<td>&nbsp;&nbsp;&nbsp;<input name="buy1" type="checkbox" value="5.00" />&nbsp;&nbsp;</td>
</tr>
<tr>
<td><img src="../book2.jpg" border="0"></td>
<td>Description of product will be here</td>
<td>&nbsp;&nbsp;&nbsp;4.50&nbsp;&nbsp;</td>
<td>&nbsp;&nbsp;&nbsp;<input name="buy2" type="checkbox" value="4.50" />&nbsp;&nbsp;</td>
</tr>
</table>

<p>
<br />
<br />
<p>
<input type="submit" value="Checkout">
</p>
</div>
</form>


checkout.php


$price = $_POST['buy'] + $_POST['buy2'];


Julian