Jump to content

Order total


Kano

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/44638-order-total/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.