JavaScript calculations

JavaScript calculations

本文关键字:calculations JavaScript      更新时间:2023-09-26

这是我的代码的更新版本。我只能在浏览器的控制台中看到p//pay rate和m//markup%的值,它们不会显示在表单loandata的指定字段中。

var b, p, m, pmp, pm, pb, fp, misc, wc, tax, sui, o, fp, misc, t;
function calculate1(){
    wc = document.set.wc.value; // workers comp %
    tax = document.set.tax.value; // taxes %
    sui = document.set.sui.value; // sui %
    o = document.set.o.value; // other expenses %
    fp =document.set.fp.value; // fund and processing %
    misc = document.set.misc.value; // Misc expenses %
    pb = (wc+tax+sui+o)/100*b; // variable used to calculate profit margin
    document.set.pb.value = pb;
    t = document.set.t.value; // target profit margin %
}
function calculate() {
    b = document.loandata.b.value; //bill rate
    b = (b=="")?(((m*p)/ 100) + p):b; 
    p = document.loandata.p.value; //pay rate 
    m = document.loandata.m.value; // markup % 
    m = (m=="")?((b-p)/p* 100):m;
    pm = (b-((pb*p)/100+(b*fp)/100+(b*misc)/100+p)); // profit margin calculation
    pm = Math.round(pm).toFixed(2);
    document.loandata.pm.value = pm;
    pmp = pm/b*100;  // profit margin % calc 
    pmp = Math.round(pmp).toFixed(2); // profit margin %
    document.loandata.pmp.value = pmp;
}
 m = (m==undefined)?(formula for m):m;
 p = (p==undefined)?(formula for p):p;