|
How do you add values from separate functions?
Can someone help. Why is this code not adding/updating the two values from these functions?
<script type="text/javascript">
var LHtotal;
var AHtotal;
var LMtotal;
var AMtotal;
var schoolTotal;
var churchTotal;
var grandTotal;
var a;
a = new Boolean();
a = false;
var newTotal1;
var newTotal2;
function calculateSchool(orgType) {
var fund = parseInt(document.getElementById(orgType + 'fund').value);
var people = parseInt(document.getElementById(orgType + 'people').value);
var percent = (parseInt(document.getElementById(orgType + 'percent').value))/100;
var active = people * percent;
active = parseInt(active);
var baskets = parseInt(document.getElementById(orgType + 'baskets').value);
var numPerYear = parseInt(document.getElementById(orgType + 'numPerYear').value);
var price = 26.00;
var commision = 0.10;
var total = fund * active * baskets * numPerYear * price * commision;
total = total.toFixed(2);
LHtotal = parseFloat(document.getElementById("LHtotal").innerHTML);
AHtotal = parseFloat(document.getElementById("AHtotal").innerHTML);
LMtotal = parseFloat(document.getElementById("LMtotal").innerHTML);
AMtotal = parseFloat(document.getElementById("AMtotal").innerHTML);
//alert(LHtotal + " " + AHtotal + " " + LMtotal + " " + AMtotal);
schoolTotal = (LHtotal + AHtotal + LMtotal + AMtotal);
//alert(schoolTotal);
if(isNaN(schoolTotal)) {
schoolTotal = "";
}
if(isNaN(active)) {
active = "";
}
if(isNaN(total)) {
total = "";
}
var Ototal = parseFloat(document.getElementById("Ototal").innerHTML);
var Etotal = parseFloat(document.getElementById("Etotal").innerHTML);
var orgTotal = (Ototal + Etotal);
var orgTotal = orgTotal.toFixed(2);
var grandTotal = (schoolTotal + orgTotal);
if(isNaN(grandTotal)) {
grandTotal = "";
}
if(isNaN(orgTotal)) {
orgTotal = "";
}
document.getElementById("orgTotal").innerHTML = orgTotal;
//document.getElementById("grandTotal").innerHTML = grandTotal;
document.getElementById(orgType + 'total').innerHTML = total;
document.getElementById(orgType + 'active').innerHTML = active;
document.getElementById("schoolTotal").innerHTML = schoolTotal;
superTotal(schoolTotal);
a = true;
;
}
function calculateChurch(orgType) {
var num = parseFloat(document.getElementById(orgType + "num").value);
var members = parseFloat(document.getElementById(orgType + "members").value);
var percent = parseFloat(document.getElementById(orgType + "percent").value)/100;
var baskets = parseFloat(document.getElementById(orgType + "baskets").value);
var fundPerYear = parseFloat(document.getElementById(orgType + "fundPerYear").value);
var total = num * members * percent * baskets * fundPerYear;
total = total.toFixed(2);
if(isNaN(total)) {
total = "";
}
document.getElementById(orgType + 'total').innerHTML = total;
var Ltotal = parseFloat(document.getElementById('Ltotal').innerHTML);
var Atotal = parseFloat(document.getElementById('Atotal').innerHTML);
churchTotal = (Ltotal + Atotal);
churchTotal = churchTotal.toFixed(2);
if(isNaN(churchTotal)) {
churchTotal = "";
}
document.getElementById("churchTotal").innerHTML = churchTotal;
a = false;
superTotal(churchTotal);
}
function superTotal(x){
var sum = document.getElementById("grandTotal").innerHTML ;
var get = x;
var what = sum + get;
document.getElementById("grandTotal").innerHTML = what;
newTotal1 = what;
}
function superTotal2(y){
newTotal2 = document.getElementById("grandTotal").innerHTML + y
document.getElementById("grandTotal").value = whole;
}
var whole = newTotal1 + newTotal2;
document.getElementById("grandTotal").innerHTML = whole;
}
</script>
Last edited by greenhat; 09-11-2012 at 09:31 PM..
|