Forum Moderators: coopster
what I'm trying to do is to add up values that are in an array, I can do this with javascript but the total that I get with javascript can't be transfered to php, so this is the code I need, to let the user choose
any of the checkboxes, this will add up the values display them onscreen then the user pays this total,
while ($row = mysql_fetch_array($result1)){echo "<tr>";
echo "<th>";echo $_SESSION['uname'] = ($row['uname']); echo "</th>";
echo "<th>";echo $_SESSION['ID'] = ($row['ID']); echo "</th>";
echo "<th>";echo $_SESSION['WOrder'] = ($row['WOrder']); echo "</th>";
echo "<th>"; echo $_SESSION['BName'] = ($row['BName']);
echo "</th>";
echo "<th>"; echo $_SESSION['FReport'] = ($row['FReport']); echo "</th>";
echo "<th>"; echo $_SESSION['amount'] = ($row['amount']); echo"</th>";
echo "<th><input type='text' name='val' value='$amount' size='7'></th>";
echo "<th><input type='checkbox' name='num[]' value='$amount'></th>";
}
//this here would be what I'm trying to do
if (num == checked)
{
$total1 = ($total1 + $amount);
}
else{
$total1 = 0;
}
I get nothing out of ten checkboxes
Php is run on the server. You can't show up a total sum to user instantly. You must process the maths in server, then return the total to the user's browser.
Javascript can show the total to user the way you need.
On the process page/script, you must recalculate the total, for the php to use it in whatever manner you wish (database storage, comparison, etc).
I can do this with javascript but the total that I get with javascript can't be transfered to php
Just perform calculations with javascript and send them to
<input type="hidden" name="total" id="total" value="0">
and in php check:
if(isset($_POST['num'])) $sum = array_sum [php.net]($_POST['num']);
Regards
Michal
And welcome to WebmasterWorld!