我有两种名为“sum”和“sub”的表格。如果我单击“sum”表单的提交按钮,则会调用函数Calculate,类似地,如果我单击“sub”表单的提交按钮,则会调用相同的函数。但我希望在调用“子”形式的计算时不应该执行“总和”形式的方法。我想这可以通过 if 语句来完成,任何人都可以告诉我这样做的语句。
function Calculate() {
var numsub=document.sub.subnum.value; //e.g: sub form assignment, this should not be executed on calling calculate from "sum" form
totnumber=totnumber-parseInt(numsub);
var sp1=document.sub.sp1.value;
var tot1=sp1*numsub;
totsellprice +=Math.floor(parseFloat(tot1));
totnumsell =parseInt(numsub) + totnumsell;
var number= document.sum.number.value;
totnumber =parseInt(number) + totnumber;
var sp= document.sum.sp.value;
var total= sp*number;
totprice +=Math.floor(parseFloat(total));
avgbuy=totprice/totnumber;
avgsell=totsellprice/totnumsell;
status= "<h1>Share status</h1>Number of shares: " + totnumber + "</br>total money spent: " + totprice;
status +="</br>Average Buying price: " + avgbuy;
status= "</br>Number of shares sold: " + totnumsell + "</br>total money earned: " + totsellprice;
status +="</br>Average Earning price: " + avgsell;
document.getElementById('results2').innerHTML= status;
}