Original Post
I am trying to script some calculations, but I am afraid I am not an expert with javascript. Can anyone tell me why my code seems to be getting stuck in the second function I call?
<head>
<title>How Much House Can My Borrower Afford?</title>
<script type = "text/javascript">
function main(form)
{
var total1;
var total2;
var total3;
var total4;
var gmi;
var mo;
var con1;
var con2;
var tmda;
var piti1;
var piti2;
var lpiti;
var factor;
var emla;
var ltv;
var empp;
gmi_b();
alert(total1);
gmi_c();
mo_b();
mo_c();
/*var total1;
var total2;
var total3;
var total4;
var gmi = total1+total2;
var mo = total3+total4;
var con1;
var con2;
var tmda = gmi*con1;
var piti1 = tmda-mo;
var piti2 = gmi*con2;
var lpiti = Math.min(piti1,piti2);
var factor;
var emla = lpiti*factor;
var ltv = eval(form.ltv.value)/[100];
var empp = emla/ltv;*/
}
function gmi_b(form)
{
if(a1 != "" || b1 != "" || c1 != "" || d1 != "" || e1 != "")
{
var a1 = eval(form.txt1.value);
var b1 = eval(form.txt2.value);
var c1 = eval(form.txt3.value);
var d1 = eval(form.txt4.value);
var e1 = eval(form.txt5.value);
var total1 = a1+b1+c1+d1+e1;
total1 = total1 * [100];
total1 = Math.round(total1)
total1 /= [100];
}
}
function gmi_c(form)
{
if(a2 != "" || b2 != "" || c2 != "" || d2 != "" || e2 != "")
{
var a2 = eval(form.txt11.value);
var b2 = eval(form.txt22.value);
var c2 = eval(form.txt33.value);
var d2 = eval(form.txt44.value);
var e2 = eval(form.txt55.value);
var total2 = a2+b2+c2+d2+e2;
total2 = total2 * [100];
total2 = Math.round(total2)
total2 /= [100];
}
}
function mo_b(form)
{
if(a3 != "" || b3 != "" || c3 != "" || d3 != "")
{
var a3 = eval(form.txt111.value);
var b3 = eval(form.txt222.value);
var c3 = eval(form.txt333.value);
var d3 = eval(form.txt444.value);
var total3 = a3+b3+c3+d3;
total3 = total3 * [100];
total3 = Math.round(total3)
total3 /= [100];
}
}
function mo_c(form)
{
if(a4 != "" || b4 != "" || c4 != "" || d4 != "")
{
var a4 = eval(form.txt1111.value);
var b4 = eval(form.txt2222.value);
var c4 = eval(form.txt3333.value);
var d4 = eval(form.txt4444.value);
var total4 = a4+b4+c4+d4;
total4 = total4 * [100];
total4 = Math.round(total4)
total4 /= [100];
}
}
</script>
</head>
<body>
<big><big>How Much House Can My Borrower Afford?</big></big>
<form id = "ltv1">
<table border="[1]" cellpadding=[5]>
<tr>
<td align=center>LTV:</td>
<td align=center>$<input type = text size = [2] name = ltv value = [0] onFocus="select()">%</td>
</tr>
</table>
</form>
<form id = "aa">
<table border="[1]" cellpadding=[5]>
<tr>
<td align=center><select>
<option value ="[15]" selected="selected">[15]</option>
<option value ="[30]">[30]</option>
</select>Year Loan</td>
<td align=center><select>
<option value ="[5].[0]" selected="selected">[5].[0]</option>
<option value ="[5].[5]">[5].[5]</option>
<option value ="[6].[0]">[6].[0]</option>
<option value ="[6].[5]">[6].[5]</option>
<option value ="[7].[0]">[7].[0]</option>
<option value ="[7].[5]">[7].[5]</option>
<option value ="[8].[0]">[8].[0]</option>
<option value ="[8].[5]">[8].[5]</option>
<option value ="[9].[0]">[9].[0]</option>
<option value ="[9].[5]">[9].[5]</option>
<option value ="[10].[0]">[10].[0]</option>
<option value ="[10].[5]">[10].[5]</option>
</select>%Rate</td>
</tr>
</table>
</form>
<big>Gross Monthly Income</big>
<form id = "a">
<table border="[1]" cellpadding=[5]>
<td align=center>For Borrower</td>
<tr>
<td align=center>Base Employment Income:</td>
<td align=center>$<input type = text name = txt1 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Overtime:</td>
<td align=center>$<input type = text name = txt2 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Part-Time:</td>
<td align=center>$<input type = text name = txt3 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Commissions:</td>
<td align=center>$<input type = text name = txt4 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Other:</td>
<td align=center>$<input type = text name = txt5 value = [0] onFocus="select()"></td>
</tr>
</table>
</form>
<form id = "b">
<table border="[1]" cellpadding=[5]>
<td align=center>For Co-Borrower</td>
<tr>
<td align=center>Base Employment Income:</td>
<td align=center>$<input type = text name = txt11 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Overtime:</td>
<td align=center>$<input type = text name = txt22 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Part-Time:</td>
<td align=center>$<input type = text name = txt33 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Commissions:</td>
<td align=center>$<input type = text name = txt44 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Other:</td>
<td align=center>$<input type = text name = txt55 value = [0] onFocus="select()"></td>
</tr>
</table>
</form>
<big>Monthly Obligations</big>
<form id = "c">
<table border="[1]" cellpadding=[5]>
<td align=center>For Borrower</td>
<tr>
<td align=center>Auto Loans:</td>
<td align=center>$<input type = text name = txt111 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Installment Loans:</td>
<td align=center>$<input type = text name = txt222 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Credit Cards:</td>
<td align=center>$<input type = text name = txt333 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Other:</td>
<td align=center>$<input type = text name = txt444 value = [0] onFocus="select()"></td>
</tr>
</table>
</form>
<form id = "d">
<table border="[1]" cellpadding=[5]>
<td align=center>For Co-Borrower</td>
<tr>
<td align=center>Auto Loans:</td>
<td align=center>$<input type = text name = txt1111 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Installment Loans:</td>
<td align=center>$<input type = text name = txt2222 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Credit Cards:</td>
<td align=center>$<input type = text name = txt3333 value = [0] onFocus="select()"></td>
</tr>
<tr>
<td align=center>Other:</td>
<td align=center>$<input type = text name = txt4444 value = [0] onFocus="select()"></td>
</tr>
</table>
</form>
<input type="button" value=" CALCULATE FORM " onClick="main(this.form)">
</body>