Kano Posted March 28, 2007 Share Posted March 28, 2007 HI there, Can someone help me please, this code works fine but I wish to add a function which adds all the <total_$wsi_id> values up and creates a grand total?? <script> function calc(obj, wsi_id) // function to create total of each order line { var ans = (obj.form.elements['price_'+wsi_id].value) * (obj.form.elements['qty_'+wsi_id].value); var res = ans.toFixed(2); obj.form.elements['total_'+wsi_id].value = res; } </script> <body> ..... while($row_getwsi = mysql_fetch_array($sqlres_getwsi)) { extract($row_getwsi); // create order line echo " <td> <input type = 'text' name = 'price_$wsi_id' value = '$wsi_price' readonly =' readonly' size = '6' maxsize = '7' /> </td> <td> <select name = 'qty_$wsi_id' onchange = 'calc(this, \"$wsi_id\")'>"; // create order line total for($selectcnt=0;$selectcnt<=$wsi_qty;$selectcnt++) { echo "<option value='$selectcnt'"; if($_SESSION[$wsi_id] == $selectcnt) { echo "selected='selected'"; } echo">$selectcnt</option>"; } echo "</select></td>"; echo"<td>$wsi_id</td> <td>$wsi_dim</td> <td><input type = 'text' name = 'total_$wsi_id' readonly = 'readonly' /> </td>"; .... <tr><td>Grand Total</td><td><input type="text" name="g_total" /></td></tr> // I wish this part to total all the order lines. .... thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.