I have 2 columns that auto sum to a subtotal. From there I need to add both subtotals together to get a grand total. I can’t figure out how to get the subtotals from the seperate functions to add together to get a grand total. Can someone please help?
JS Code:
<script type=”text/javascript”>
function calcTotal(txtBox, totBox) {
totBox = document.getElementById(totBox);
var totVal = Number(totBox.value);
var txtVal = Number(txtBox.value);
if ( isNaN(txtVal) ) {
alert(“Please only enter numbers.”);
txtBox.select();
txtBox.focus();
} else {
if ( isNaN(totVal) ) {
totVal = 0;
}
totBox.value = totVal + txtVal;
}
txtBox = null;
totBox = null;
}
function calcTotal(txt1Box, tot1Box) {
tot1Box = document.getElementById(tot1Box);
var tot1Val = Number(tot1Box.value);
var txt1Val = Number(txt1Box.value);
if ( isNaN(txt1Val) ) {
alert(“Please only enter numbers.”);
txt1Box.select();
txt1Box.focus();
} else {
if ( isNaN(tot1Val) ) {
tot1Val = 0;
}
tot1Box.value = tot1Val + txt1Val;
}
txt1Box = null;
tot1Box = null;
}
</script>
HTML Code:
<table width=”600″ border=”0″ align=”center” cellpadding=”5″>
<caption>
Borrower Co-Borrower
</caption>
<tr>
<td width=”321″>Credit Cards <span style=”font-size: small”>(Minimum Monthly Payments)</span></td>
<td width=”161″>$<input type=”text” onblur=”calcTotal(this, ‘tot’)” size=”20″ /></td>
<td width=”161″>$<input type=”text” onblur=”calcTotal(this, ‘tot1’)” size=”20″ /></td>
</tr>
<tr>
<td>Car Loans <span style=”font-size: small”>(Minimum Monthly Payments)</span></td>
<td>$<input type=”text” onblur=”calcTotal(this, ‘tot’)” size=”20″ /></td>
<td>$<input type=”text” onblur=”calcTotal(this, ‘tot1’)” size=”20″ /></td>
</tr>
<tr>
<td>Student Loans</td>
<td>$<input type=”text” onblur=”calcTotal(this, ‘tot’)” size=”20″ /></td>
<td>$<input type=”text” onblur=”calcTotal(this, ‘tot1’)” size=”20″ /></td>
</tr>
<tr>
<td>Installment Loans</td>
<td>$<input type=”text” onblur=”calcTotal(this, ‘tot’)” size=”20″ /></td>
<td>$<input type=”text” onblur=”calcTotal(this, ‘tot1’)” size=”20″ /></td>
</tr>
<tr>
<td>Home Equity Loans</td>
<td>$<input type=”text” onblur=”calcTotal(this, ‘tot’)” size=”20″ /></td>
<td>$<input type=”text” onblur=”calcTotal(this, ‘tot1’)” size=”20″ /></td>
</tr>
<tr>
<td>Alimony/Child Support</td>
<td>$<input type=”text” onblur=”calcTotal(this, ‘tot’)” size=”20″ /></td>
<td>$<input type=”text” onblur=”calcTotal(this, ‘tot1’)” size=”20″ /></td>
</tr>
<tr>
<td>Other Monthly Debt</td>
<td>$<input type=”text” onblur=”calcTotal(this, ‘tot’)” size=”20″ /></td>
<td>$<input type=”text” onblur=”calcTotal(this, ‘tot1’)” size=”20″ /></td>
</tr>
<tr>
<td>Monthly Subtotal</td>
<td>$<input type=”text” id=”tot” size=”20″ /></td>
<td>$<input type=”text” id=”tot1″ size=”20″ /></td>
</tr>
<tr>
<td style=”font-weight: bold”>Monthly Total</td>
<td colspan=”2″ style=”text-align: center”>$<input type=”text” id=”tot2″ size=”20″ /></td>
</tr>
</table>