Forum Moderators: coopster
I have 4 check boxes (r1, r2, r3, r4)
$r1 = A
$r2 = B
$r3 = C
$r4 = NY
I then have a hidden field $region (to collect values to be entered into database)
<input name="region" type="hidden" value="<?php echo ("$r1 $r2 $r3 $r4");?>">
So $region is entered into the database. easy.
THAT WORKS FINE. The tricky part.
I have a second set of values that needs to be calculated at the same time.
$r1 also = 167
$r2 also = 61
$r3 also = 24
$r4 also = 12
I then have another hidden field called $quanity
$quanity = ("$r1 + $r2 + $r3 + $r4");
which returns the calculated value, so quanity = 86, or whatever the sum of the checkbox values is.
Lots of info, confusing?
Masters go to Work!
Thanks for any help at all!
Then the values should have values:
$r1 also = 167
$r2 also = 61
$r3 also = 24
$r4 also = 12
You could do:
$r['A'] = 167;
$r['B'] = 61;
$r['C'] = 24;
$r['NY'] = 12;
btw. do you have the integer values for A, B, C and NY in a database? If so, you can do the calculations in a sql query!
<form method="post" action="junk.php">
<p><input type="checkbox" name="fields[A]" value="123">Region A</p>
<p><input type="checkbox" name="fields[B]" value="345">Region B</p>
<p><input type="checkbox" name="fields[C]" value="678">Region C</p>
<p><input type="checkbox" name="fields[NY]" value="910">Region NY</p>
<p><input type="submit" name="sub1" value="Select Region(s)"></p>
</form>
<?
if(isset($_POST['fields']))
{
$content = "";
foreach($_POST['fields'] as $key => $val)
{
$content .= "\n<li>Region $key: $val</li>";
}
echo "<ul>" . $content . "</ul><pre>\n\n\n";
print_r($_POST);
echo "</pre>";
}
?>
The form has the following check boxes...
<input name="r1" type="checkbox" value="A">
<input name="r2" type="checkbox" value="B">
<input name="r3" type="checkbox" value="C">
<input name="r4" type="checkbox" value="NY">
Then the page that processes the form data has...
<?php
if ($r1 == "A") {
$rNumber1 = "167";
} else {
$rNumber1 = "0";
}
if ($r2 == "B") {
$rNumber2 = "61";
} else {
$rNumber2 = "0";
}
if ($r3 == "C") {
$rNumber3 = "24";
} else {
$rNumber3 = "0";
}
if ($r4 == "NY") {
$rNumber4 = "12";
} else {
$rNumber4 = "0";
}
$finalNumber = ('$rNumber1' + '$rNumber2' + '$rNumber3' + '$rNumber4');
?>
SO $region is assigned values $r1, $r2, $r3, $r4
And the numerical calculation is $finalNumber
Thanks for all your help, though.