How to calculate subtotal,tax,packingcharges and others charges in javascript and php?

I have written a functions to calculate subtotal+tax+Other Charges.
function mkTotal() {
stot = parseInt(document.getElementById('stot').value);
fwd = parseInt(document.getElementById('fwd').value);
oth1 = parseInt(document.getElementById('oth1').value);
var tax_rate = parseInt(document.getElementById('tax0').value);
var tax = stot * (tax_rate/100);
document.getElementById('tax1').value = tax;

var total = stot + tax + fwd + oth1;
total = Math.round(total);
document.getElementById('net').value = total;


but the problem is in this line: tax rate is fetched by AJAX respond text 'txtHint3'.
<td width="142" ><select name="tax_name" onchange="showUser3(this.value)" >
<option selected="selected" disabled="disabled">Choose Tax Name</option>
$sql01=mysql_query("select * from tax_master order by id ASC");
<option> <?php print $val01['tax_name'];?> </option>
<?php } ?>
</select> </td>
<td width="246" ><div align="right" id="txtHint3"><strong>Choose tax name First </strong></div></td>
<td width="160"><input type="text" name="tax_amt" value="" style="text-align:right" id="tax1" readonly="true" /></td>

<tr >

This is the pic of my work

I want it to be calculated as I choose tax name from the drop down list.
1. In 1st row 'Gtotal of sale enries' is the total calculation of sales.
2. In 2nd row Drop down list of tax names.
3. next box is of tax rate fetched by Ajax.
4. The last box in 2nd row is for calculation of tax amount(should contain 0.00 if no tax is selected).
5. 3rd Row is for adding packing & forwarding Charges(should contain 0.00 if no value is available).
6. 4rth Row is for other Charges(should contain 0.00 if no value is available).
7. The last Row is for Gross Total.

I Hope you understand the problem and can help me.
This is what I understand
In the 2nd row you have two text boxes. First one ( small one ) will list the tax rate after selection of tax type from the drop down list.
Once this value or percentage of tax is available the right most text box will calculate the tax based on the tax rate and the Total Sales Entries. Other text boxes are for entry only and based on these the final rate will be calculated.

All the calculations can be done by JavaScript.
Use the onblur event to trigger the calculations.
Using this concept a good tax calculator can be developed.
Ya that's it. Thanks a lot again!!!
Please Login to post your reply or start a new topic