如何在javascript

时间:2018-05-18 10:57:24

标签: javascript php loops calculation

我正在使用JavaScript动态显示文本框

enter image description here

和计算在javascript中使用

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;
}

如何查找税收总额此处显示最后输入值我必须显示税收amt字段的每次点击显示以下列中的总计如何计算?

1 个答案:

答案 0 :(得分: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);
}