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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.