faqts : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

15 of 18 people (83%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How can I setup a form that counts the number of checkboxes the user selects, then multiplies that number times a dollar amount to achieve a total.

Mar 23rd, 2001 14:59
Ben Udall, Eric Thomas,


Here's a quick example:
<form action="process.php" method="post">
<input type="checkbox" name="cbox[]" value="1" />
<input type="checkbox" name="cbox[]" value="1" />
<input type="checkbox" name="cbox[]" value="1" />
</form>
In the form processing script (process.php):
<?
$amount = 6.50;
$total  = count($cbox) * $amount;
echo 'Total: $'.$total;
?>