0

I am using JavaScript to show text box dynamically

enter image description here

and calculations are used in javascript like

function add_number(k) {
    var rate = parseFloat(document.getElementById("rate-"+k).value);
    var units = parseFloat(document.getElementById("unit-"+k).value);
    var disc = parseFloat(document.getElementById("dis-"+k).value);
    var result = rate * units;
    var discnt =result - disc;
    var disamt =parseFloat(discnt).toFixed(2);
    var utgp = 9;
    var persnt = parseFloat((discnt * utgp) /100).toFixed(2);
    var totl = discnt +(persnt * 2);
    var totls = parseFloat(totl).toFixed(2);
    document.getElementById("taxs-"+k).value = disamt;
    document.getElementById("utgp-"+k).value = utgp;
    document.getElementById("utg-"+k).value = persnt;
    document.getElementById("cgstp-"+k).value = utgp;
    document.getElementById("cgst-"+k).value = persnt;
    document.getElementById("total-"+k).value = totls;
    document.getElementById("taxtotal").value = disamt;
}

how to find tax total here show last enter value I have to show every click of tax amt field show total in below column how to calculate ?

1 Answer 1

1
#This may Help you out#
var total=0;
function add_number(k) {
var rate = parseFloat(document.getElementById("rate-"+k).value);
var units =parseFloat(document.getElementById("unit-"+k).value);
var disc = parseFloat(document.getElementById("dis-"+k).value);
var result = rate * units;
var discnt =result - disc;
var disamt =parseFloat(discnt).toFixed(2);
var utgp = 9;
var persnt = parseFloat((discnt * utgp) /100).toFixed(2);
var totl = discnt +(persnt * 2);
var totls = parseFloat(totl).toFixed(2);
document.getElementById("taxs-"+k).value = disamt;
document.getElementById("utgp-"+k).value = utgp;
document.getElementById("utg-"+k).value = persnt;
document.getElementById("cgstp-"+k).value = utgp;
document.getElementById("cgst-"+k).value = persnt;
document.getElementById("total-"+k).value = totls;
document.getElementById("taxtotal").value = disamt;
total = parseFloat(total)+parseFloat(totls);
alert(total);
}
Sign up to request clarification or add additional context in comments.

2 Comments

and concatenate 1+1=11 why ? i will the add two numbers are !NaN ,so why the answer show this type.......
1] Please add "parseFloat" while adding. 2] document.getElementById("taxs-"+k).value = disamt; change all these into disamt = document.getElementById("taxs-"+k).value;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.