Live Javascript calculating
Hi there!
I hope one of you javascript experts can help me out on this one. In html and PHP I made a purchase script. Al the products are listed inside a WHILE loop. The problem is, when I POST it starts entering data in the database. I would like the possibility that when I enter a number in the "aantal" field that it instantly calculates live how much it is going to cost.
So, "aantal$i" * inkoop_prijs = Subtotal
And, all Subtotals together = Total
Big respect to the one that solves this ;)
Code:
<?php
if(isset($leverancier_id)) {
$i = 1;
$totaal = 0;
while($prodinfo = mysql_fetch_assoc($prodres)) {
?>
<tr>
<td><?=$prodinfo['product_id'];?></td>
<td><?=$prodinfo['naam'];?></td>
<td align="center"><input name="aantal<?=$i;?>" type="text" value="" size="5" /></td>
<td><?=number_format($prodinfo['inkoop_prijs'], 2);?></td>
<td align="right">Subtotal</td>
</tr>
<input type="hidden" name="product_id<?=$i;?>" value="<?=$prodinfo['product_id'];?>" />
<input type="hidden" name="inkoop_prijs<?=$i;?>" value="<?=$prodinfo['inkoop_prijs'];?>" />
<?php
$i++;
} }
?>
<tr>
<td colspan="2" valign="top" align="right"><strong>Totaal:</strong></td>
<td colspan="2" valign="top">incl. 19% BTW </td>
<td align="right"><strong>Total</strong></td>
</tr>