I am building an app for a mortgage company. In the scenario portion(to figure mortgages with variable values) I have a series of textboxs using the onblur event. They simply take the values input to the form field and run math equations. I had them working and went on to another module of the application. I have finished with the new module (which does not interact with the function in question) and during a review with my boss we noticed the onblur function was not working. Using the Firebug ext. for FF I discovered that the browser (ff) is telling me that my function tmp() is not a function. In IE it tells me that the object does not support this property or method. I cant see why i am getting these issues all of a sudden. Can you all please take a look at my code and see if I have done something stupid or overlooked something?
Here is the js function:
//get total month payment
function tmp()
{
if (document.getElementById('calc1_est_monthPayment').value != ("") &&
document.getElementById('calc1_hazardIns').value != ("") &&
document.getElementById('calc1_taxes').value != ("") &&
document.getElementById('calc1_MIP').value != ("") &&
document.getElementById('calc1_HOADues').value != ("") &&
document.getElementById('calc1_ttlMonthPmt').value != (""))
{
var c1emp=document.getElementById('calc1_est_monthPayment').value; c1emp = Number(c1emp);
var scc1hi=document.getElementById('calc1_hazardIns').value; scc1hi = Number(scc1hi);
var scc1t=document.getElementById('calc1_taxes').value; scc1t = Number(scc1t);
var c1mi=document.getElementById('calc1_MIP').value; c1mi = Number(c1mi);
var scc1hoad=document.getElementById('calc1_HOADues').value; scc1hoad = Number(scc1hoad);
//var cttlmp=document.getElementById('calc1_ttlMonthPmt').value; cttlmp = Number(cttlmp);
var scc1TTLMOPMT=document.getElementById('calc1_ttlMonthPmt');
scc1TTLMOPMT.value=c1emp+c1mi+scc1hi+scc1t+scc1hoad;
}
}
The code above is a snippet of a larger script. i will post the rest of the js in case it something that has to do with when the function is declared.
Full js file:
/* scenario.js
* Copyright 2009 Community Lending Group LLC www.affordablecommunities.com
* NOT Licensed for use by any entity except CLG or affiliate
* Author: Stephen Nielsen
* Author Email: stephen@affordablecommunities.com
* AUthor pub email: uncamoe@gmail.com
*/
/*
function getPayOff_refi()
{
*/
function grabFirstMortBal(val)
{
//grab first mortgage bal if not empty, place that value in refi fields in scenarios
if(document.getElementById('1st_balance').value != "")
{
document.getElementById('calc1_refi').value=document.getElementById('1st_balance').value;
document.getElementById('calc2_refi').value=document.getElementById('1st_balance').value;
var spanTag = document.createElement("span");
spanTag.id = "span1";
spanTag.className ="dynamicSpan";
spanTag.innerHTML=val;
document.getElementById('tbp').appendChild(spanTag);
}
} // END:function grabFirstMortBal()
function grabSecMortBal(val)
{
//grab first and second mortgage bal if not empty, add those values
//and place that updated value in refi fields in scenarios
if(document.getElementById('1st_balance').value != "" && document.getElementById('2nd_balance').value != "")
{
var fBal=document.getElementById('1st_balance').value; fBal = Number(fBal);
var sBal=document.getElementById('2nd_balance').value; sBal = Number(sBal);
var scen1_SubBal_ttl=document.getElementById('calc1_refi');
scen1_SubBal_ttl.value=fBal+sBal;
var scen2_SubBal_ttl=document.getElementById('calc2_refi');
scen2_SubBal_ttl.value=fBal+sBal;
var spanTag = document.createElement("span");
spanTag.id = "span1";
spanTag.className ="dynamicSpan";
spanTag.innerHTML=val;
document.getElementById('tbp').appendChild(spanTag);
}
}// END:function grabSecMortBal()
function grabThirdMortBal(val)
{
//grab first, second and third mortgage bal if not empty, add those values
//and place that updated value in refi fields in scenarios
if(document.getElementById('1st_balance').value != "" && document.getElementById('2nd_balance').value != "" && document.getElementById('3rd_balance').value != "")
{
var fBal=document.getElementById('1st_balance').value; fBal = Number(fBal);
var sBal=document.getElementById('2nd_balance').value; sBal = Number(sBal);
var tBal=document.getElementById('3rd_balance').value; tBal = Number(tBal);
var scen1_SubBal_ttl=document.getElementById('calc1_refi');
scen1_SubBal_ttl.value=fBal+sBal+tBal;
var scen2_SubBal_ttl=document.getElementById('calc2_refi');
scen2_SubBal_ttl.value=fBal+sBal+tBal;
var spanTag = document.createElement("span");
spanTag.id = "span1";
spanTag.className ="dynamicSpan";
spanTag.innerHTML=val;
document.getElementById('tbp').appendChild(spanTag);
}
} // END:function grabThirdMortBal()
function getRefi()
{
/*payOff3Yes*/
if (document.getElementById('sc_payOffVal1').value != "" && document.getElementById('sc_payOffVal2').value != "" && document.getElementById('sc_payOffVal3').value != "")
{
var sc_fBal=document.getElementById('sc_payOffVal1').value; sc_fBal = Number(sc_fBal);
var sc_sBal=document.getElementById('sc_payOffVal2').value; sc_sBal = Number(sc_sBal);
var sc_tBal=document.getElementById('sc_payOffVal3').value; sc_tBal = Number(sc_tBal);
var refi_sb=document.getElementById('calc1_refi').value; refi_sb = Number(refi_sb);
var scen1_Refi_ttl=document.getElementById('calc1_refi');
scen1_Refi_ttl.value=sc_fBal+sc_sBal+sc_tBal+refi_sb;
}
} // END getRefi
function getRefi2()
{
/*payOff3Yes*/
if (document.getElementById('scTwo_payOffVal1').value != "" && document.getElementById('scTwo_payOffVal2').value != "" && document.getElementById('scTwo_payOffVal3').value != "")
{
var sc_fBal=document.getElementById('scTwo_payOffVal1').value; sc_fBal = Number(sc_fBal);
var sc_sBal=document.getElementById('scTwo_payOffVal2').value; sc_sBal = Number(sc_sBal);
var sc_tBal=document.getElementById('scTwo_payOffVal3').value; sc_tBal = Number(sc_tBal);
var refi_sb=document.getElementById('calc2_refi').value; refi_sb = Number(refi_sb);
var scen1_Refi_ttl=document.getElementById('calc2_refi');
scen1_Refi_ttl.value=sc_fBal+sc_sBal+sc_tBal+refi_sb;
}
} // END getRefi
//this function takes the values from the mortgages and the payoff liabilities and adds them
// for a grand total (Refi amount)
function totalPayOff()
{
var total = 0;
var totalMth = 0;
if(document.getElementById('payOffMtg1Yes').checked == true) {
total += parseFloat(document.getElementById('payOffMtg1Yes').value);
}
if(document.getElementById('payOffMtg1Yes').checked == true) { totalMth += parseFloat(document.getElementById('firstPayOffMth').value); }
if(document.getElementById('payOffMtg2Yes').checked == true) { total += parseFloat(document.getElementById('payOffMtg2Yes').value); }
if(document.getElementById('payOffMtg2Yes').checked == true) { totalMth += parseFloat(document.getElementById('secondPayOffMth').value); }
if(document.getElementById('payOff1Yes').checked == true) { total += parseFloat(document.getElementById('payOff1Yes').value); }
if(document.getElementById('payOff1Yes').checked == true) { totalMth += parseFloat(document.getElementById('sc_payOffMthVal1').value); }
if(document.getElementById('payOff2Yes').checked == true) { total += parseFloat(document.getElementById('payOff2Yes').value); }
if(document.getElementById('payOff2Yes').checked == true) { totalMth += parseFloat(document.getElementById('sc_payOffMthVal2').value); }
if(document.getElementById('payOff3Yes').checked == true) { total += parseFloat(document.getElementById('payOff3Yes').value); }
if(document.getElementById('payOff3Yes').checked == true) { totalMth += parseFloat(document.getElementById('sc_payOffMthVal3').value); }
if(document.getElementById('payOff4Yes').checked == true) { total += parseFloat(document.getElementById('payOff4Yes').value); }
if(document.getElementById('payOff4Yes').checked == true) { totalMth += parseFloat(document.getElementById('sc_payOffMthVal4').value); }
//if(document.mortupdate.d.checked == true) { total += parseFloat(document.F2.d.value); }
var ts = new String(total);
if(ts.indexOf('.') < 0) { ts += '.00'; }
if(ts.indexOf('.') == (ts.length - 2)) { ts += '0'; }
document.getElementById('sc_payOffTtl').value = ts;
document.getElementById('calc1_refi').value=ts;
var tsMth = new String(totalMth);
if(tsMth.indexOf('.') < 0) { tsMth += '.00'; }
if(tsMth.indexOf('.') == (tsMth.length - 2)) { tsMth += '0'; }
document.getElementById('calc1_mnthPayOffTtl').value = tsMth;
}
//this function takes any debt (to be paid) that is not included in the pay off and adds them for the DTI Bottom
function totalNotPayOff()
{
var totalnp = 0;
var totalnpMth = 0;
var totalnpG = 0;
//var emptyEl = document.getElementById('');
// mortgages
if (document.getElementById('firstPayOffMth').value == null) {
document.getElementById('firstPayOffMth').value = ("0.00");
if(document.getElementById('payOffMtg1Yes').checked == false) { totalnp += parseFloat(document.getElementById('payOffMtg1Yes').value); }
if(document.getElementById('payOffMtg1Yes').checked == false) { totalnpMth += parseFloat(document.getElementById('firstPayOffMth').value); }
if(document.getElementById('payOffMtg1Yes').checked == false) { totalnpG += parseFloat(document.getElementById('firstPayOff').value); }
} else {
if(document.getElementById('payOffMtg1Yes').checked == false) { totalnp += parseFloat(document.getElementById('payOffMtg1Yes').value); }
if(document.getElementById('payOffMtg1Yes').checked == false) { totalnpMth += parseFloat(document.getElementById('firstPayOffMth').value); }
if(document.getElementById('payOffMtg1Yes').checked == false) { totalnpG += parseFloat(document.getElementById('firstPayOff').value); }
}
if (document.getElementById('secondPayOffMth').value == null) { // if the element has not been create it then use values
document.getElementById('secondPayOffMth').value = ("0.00");
if(document.getElementById('payOffMtg2Yes').checked == false) { totalnp += parseFloat(document.getElementById('payOffMtg2Yes').value); }
if(document.getElementById('payOffMtg2Yes').checked == false) { totalnpMth += parseFloat(document.getElementById('secondPayOffMth').value); }
if(document.getElementById('payOffMtg2Yes').checked == false) { totalnpG += parseFloat(document.getElementById('secondPayOff').value); }
} else {
if(document.getElementById('payOffMtg2Yes').checked == false) { totalnp += parseFloat(document.getElementById('payOffMtg2Yes').value); }
if(document.getElementById('payOffMtg2Yes').checked == false) { totalnpMth += parseFloat(document.getElementById('secondPayOffMth').value); }
if(document.getElementById('payOffMtg2Yes').checked == false) { totalnpG += parseFloat(document.getElementById('secondPayOff').value); }
}
// liabilities
if (document.getElementById('sc_payOffMthVal1').value == null) { // if the element has not been create it then use values
document.getElementById('sc_payOffMthVal1').value = ("0.00");
if(document.getElementById('payOff1Yes').checked == false) { totalnp += parseFloat(document.getElementById('payOff1Yes').value); }
if(document.getElementById('payOff1Yes').checked == false) { totalnpMth += parseFloat(document.getElementById('sc_payOffMthVal1').value); }
} else {
if(document.getElementById('payOff1Yes').checked == false) { totalnp += parseFloat(document.getElementById('payOff1Yes').value); }
if(document.getElementById('payOff1Yes').checked == false) { totalnpMth += parseFloat(document.getElementById('sc_payOffMthVal1').value); }
}
if (document.getElementById('sc_payOffMthVal2').value == null) { // if the element has not been create it then use values
document.getElementById('sc_payOffMthVal2').value = ("0.00");
if(document.getElementById('payOff2Yes').checked == false) { totalnp += parseFloat(document.getElementById('payOff2Yes').value); }
if(document.getElementById('payOff2Yes').checked == false) { totalnpMth += parseFloat(document.getElementById('sc_payOffMthVal2').value); }
} else {
if(document.getElementById('payOff2Yes').checked == false) { totalnp += parseFloat(document.getElementById('payOff2Yes').value); }
if(document.getElementById('payOff2Yes').checked == false) { totalnpMth += parseFloat(document.getElementById('sc_payOffMthVal2').value); }
}
if (document.getElementById('payOff3Yes').value == null) { // if the element has not been create it then use values
document.getElementById('payOff3Yes').value = ("0.00");
if(document.getElementById('payOff3Yes').checked == false) { totalnp += parseFloat(document.getElementById('payOff3Yes').value); }
if(document.getElementById('payOff3Yes').checked == false) { totalnpMth += parseFloat(document.getElementById('sc_payOffMthVal3').value); }
} else {
if(document.getElementById('payOff3Yes').checked == false) { totalnp += parseFloat(document.getElementById('payOff3Yes').value); }
if(document.getElementById('payOff3Yes').checked == false) { totalnpMth += parseFloat(document.getElementById('sc_payOffMthVal3').value); }
}
if (document.getElementById('sc_payOffMthVal4').value == null) { // if the element has not been create it then use values
document.getElementById('sc_payOffMthVal4').value = ("0.00");
if(document.getElementById('payOff4Yes').checked == false) { totalnp += parseFloat(document.getElementById('payOff4Yes').value); }
if(document.getElementById('payOff4Yes').checked == false) { totalnpMth += parseFloat(document.getElementById('sc_payOffMthVal4').value); }
} else {
if(document.getElementById('payOff4Yes').checked == false) { totalnp += parseFloat(document.getElementById('payOff4Yes').value); }
if(document.getElementById('payOff4Yes').checked == false) { totalnpMth += parseFloat(document.getElementById('sc_payOffMthVal4').value); }
}
var tsnpMth = new String(totalnpMth);
if(tsnpMth.indexOf('.') < 0) { tsnpMth += '.00'; }
if(tsnpMth.indexOf('.') == (tsnpMth.length - 2)) { tsnpMth += '0'; }
document.getElementById('bh').value = tsnpMth;
var tsnpgross = new String(totalnpG);
if(tsnpgross.indexOf('.') < 0) { tsnpgross += '.00'; }
if(tsnpgross.indexOf('.') == (tsnpgross.length - 2)) { tsnpgross += '0'; }
document.getElementById('mtghidden').value = tsnpgross;
var c1tmpmt=document.getElementById('calc1_ttlMonthPmt').value; c1tmpmt = Number(c1tmpmt);
var loanAmount=document.getElementById('calc1_loanAmount').value; loanAmount = Number(loanAmount);
var mtggross=document.getElementById('mtghidden').value; mtggross = Number(mtggross);
var homevalue=document.getElementById('hv').value; homevalue = Number(homevalue);
var grossIncome=document.getElementById('gi').value; grossIncome = Number(grossIncome);
var debtPayment=document.getElementById('bh').value; debtPayment = Number(debtPayment);
// get Combined Loan to Value
var c1cltv=document.getElementById('calc1_CLTV');
c1cltv.value=Math.round(((loanAmount+mtggross)/homevalue)*100);
document.getElementById('calc1_LTV').innerHTML = c1cltv + "%";
// get bottom
var c1bottom=document.getElementById('calc1_Bottom');
c1bottom.value=Math.round(((debtPayment+c1tmpmt)/grossIncome)*100);
document.getElementById('calc1_Bottom').innerHTML = c1bottom + "%";
}
//this function takes the values from the mortgages and the payoff liabilities and adds them
// for a grand total (Refi amount)
function scTwo_totalPayOff()
{
var total2 = 0;
if(document.getElementById('scTwo_payOffMtg1Yes').checked == true) {
total2 += parseFloat(document.getElementById('scTwo_payOffMtg1Yes').value);
}
if(document.getElementById('scTwo_payOffMtg2Yes').checked == true) { total2 += parseFloat(document.getElementById('scTwo_payOffMtg2Yes').value); }
if(document.getElementById('scTwo_payOff1Yes').checked == true) { total2 += parseFloat(document.getElementById('scTwo_payOff1Yes').value); }
if(document.getElementById('scTwo_payOff2Yes').checked == true) { total2 += parseFloat(document.getElementById('scTwo_payOff2Yes').value); }
if(document.getElementById('scTwo_payOff3Yes').checked == true) { total2 += parseFloat(document.getElementById('scTwo_payOff3Yes').value); }
if(document.getElementById('scTwo_payOff4Yes').checked == true) { total2 += parseFloat(document.getElementById('scTwo_payOff4Yes').value); }
var ts2 = new String(total2);
if(ts2.indexOf('.') < 0) { ts2 += '.00'; }
if(ts2.indexOf('.') == (ts2.length - 2)) { ts2 += '0'; }
document.getElementById('scTwo_payOffTtl').value = ts2;
document.getElementById('calc2_refi').value=ts2;
}
function tbpOffTtl()
{
if (document.getElementById('firstPayOff').value != "" &&
document.getElementById('secondPayOff').value != "" &&
document.getElementById('sc_payOffVal1').value != "" &&
document.getElementById('sc_payOffVal2').value != "" &&
document.getElementById('sc_payOffVal3').value != "")
{
var sc_pOFM=document.getElementById('firstPayOff').value; sc_pOFM = Number(sc_pOFM);
var sc_pOSM=document.getElementById('secondPayOff').value; sc_pOSM = Number(sc_pOSM);
var sc_fBal=document.getElementById('sc_payOffVal1').value; sc_fBal = Number(sc_fBal);
var sc_sBal=document.getElementById('sc_payOffVal2').value; sc_sBal = Number(sc_sBal);
var sc_tBal=document.getElementById('sc_payOffVal3').value; sc_tBal = Number(sc_tBal);
var sc_POTTL=document.getElementById('sc_payOffTtl');
sc_POTTL.value=sc_pOFM+sc_pOSM+sc_fBal+sc_sBal+sc_tBal;
}
}
function scTwo_tbpOffTtl()
{
if (document.getElementById('scTwo_firstPayOff').value != "" &&
document.getElementById('scTwo_secondPayOff').value != "" &&
document.getElementById('scTwo_payOffVal1').value != "" &&
document.getElementById('scTwo_payOffVal2').value != "" &&
document.getElementById('scTwo_payOffVal3').value != "")
{
var sc_pOFM=document.getElementById('scTwo_firstPayOff').value; sc_pOFM = Number(sc_pOFM);
var sc_pOSM=document.getElementById('scTwo_secondPayOff').value; sc_pOSM = Number(sc_pOSM);
var sc_fBal=document.getElementById('scTwo_payOffVal1').value; sc_fBal = Number(sc_fBal);
var sc_sBal=document.getElementById('scTwo_payOffVal2').value; sc_sBal = Number(sc_sBal);
var sc_tBal=document.getElementById('scTwo_payOffVal3').value; sc_tBal = Number(sc_tBal);
var sc_POTTL=document.getElementById('scTwo_payOffTtl');
sc_POTTL.value=sc_pOFM+sc_pOSM+sc_fBal+sc_sBal+sc_tBal;
}
}
/*
}
*/ // END:__ function getPayOff_refi()
// update pay off Summary
function updatePayoffSummary(id,shtml)
{
if(document.getElementById || document.all)
{
var el=document.getElementById? document.getElementById(id): document.all[id];
if(el&&typeof el.innerHTML!="undefined")
{
el.innerHTML=shtml;
}
}
}
function createSpan(val)
{
var spanTag = document.createElement("span");
spanTag.id = "span1";
spanTag.className ="dynamicSpan";
spanTag.innerHTML=val;
document.getElementById('tbp').appendChild(spanTag);
}
// END:__ update pay off Summary
// update pay off Summary calc2
function updatePayoffSummary2(id,shtml)
{
if(document.getElementById || document.all)
{
var el=document.getElementById? document.getElementById(id): document.all[id];
if(el&&typeof el.innerHTML!="undefined")
{
el.innerHTML=shtml;
}
}
}
function createSpan2(val)
{
var spanTag = document.createElement("span");
spanTag.id = "span1";
spanTag.className ="dynamicSpan";
spanTag.innerHTML=val;
document.getElementById('tbp2').appendChild(spanTag);
}
// END:__ update pay off Summary calc2
//get total month payment
function tmp()
{
if (document.getElementById('calc1_est_monthPayment').value != ("") &&
document.getElementById('calc1_hazardIns').value != ("") &&
document.getElementById('calc1_taxes').value != ("") &&
document.getElementById('calc1_MIP').value != ("") &&
document.getElementById('calc1_HOADues').value != ("") &&
document.getElementById('calc1_ttlMonthPmt').value != (""))
{
var c1emp=document.getElementById('calc1_est_monthPayment').value; c1emp = Number(c1emp);
var scc1hi=document.getElementById('calc1_hazardIns').value; scc1hi = Number(scc1hi);
var scc1t=document.getElementById('calc1_taxes').value; scc1t = Number(scc1t);
var c1mi=document.getElementById('calc1_MIP').value; c1mi = Number(c1mi);
var scc1hoad=document.getElementById('calc1_HOADues').value; scc1hoad = Number(scc1hoad);
//var cttlmp=document.getElementById('calc1_ttlMonthPmt').value; cttlmp = Number(cttlmp);
var scc1TTLMOPMT=document.getElementById('calc1_ttlMonthPmt');
scc1TTLMOPMT.value=c1emp+c1mi+scc1hi+scc1t+scc1hoad;
}
}
// grab values and gets the correct value for TOP DTI
function top()
{
if (document.getElementById('gi').value != ("") && document.getElementById('first_mpayment').value != (""))
{
var givalue=document.getElementById('gi').value; givalue = Number(givalue);
var calc1_ttlMonthPmt=document.getElementById('calc1_ttlMonthPmt').value; calc1_ttlMonthPmt = Number(calc1_ttlMonthPmt);
var c1top=document.getElementById('calc1_top');
if (document.getElementById('payOffMtg1Yes').checked == false) {
var mtgPayvalue=document.getElementById('first_mpayment').value; mtgPayvalue = Number(mtgPayvalue);
var x = ("y");
}
if (document.getElementById('payOffMtg2Yes').checked == false) {
var secmtgPayvalue=document.getElementById('second_mpayment').value; secmtgPayvalue = Number(secmtgPayvalue);
var z = ("y");
}
if (x == ("y") && z == ("y")) {
c1top.value=Math.round(((secmtgPayvalue+mtgPayvalue+calc1_ttlMonthPmt)/givalue)*100);
document.getElementById('calc1_top').innerHTML = c1top + "%";
} else
if (x == ("y")) {
c1top.value=Math.round(((mtgPayvalue+calc1_ttlMonthPmt)/givalue)*100);
document.getElementById('calc1_top').innerHTML = c1top + "%";
} else
if (z == ("y")) {
c1top.value=Math.round(((secmtgPayvalue+calc1_ttlMonthPmt)/givalue)*100);
document.getElementById('calc1_top').innerHTML = c1top + "%";
} else {
c1top.value=Math.round((calc1_ttlMonthPmt/givalue)*100);
document.getElementById('calc1_top').innerHTML = c1top + "%";
}
}
}
function bottom()
{
if(document.getElementById('gi').value != ("") && document.getElementById('calc1_mnthPayOffTtl').value != (""))
{
var givalue2=document.getElementById('gi').value; givalue2 = Number(givalue2);
var c1mpot=document.getElementById('calc1_mnthPayOffTtl').value; c1mpot = Number(c1mpot);
var c1bottom=document.getElementById('calc1_Bottom');
c1bottom.value=Math.round((c1mpot/givalue2)*100);
document.getElementById('calc1_Bottom').innerHTML = c1bottom + "%";
}
}
function ltv()
{
if(document.getElementById('calc1_loanAmount').value != ("") && document.getElementById('hv').value != (""))
{
var c1fb=document.getElementById('calc1_loanAmount').value; c1fb = Number(c1fb);
var c1hv=document.getElementById('hv').value; c1hv = Number(c1hv);
var c1ltv=document.getElementById('calc1_LTV');
c1ltv.value=Math.round((c1fb/c1hv)*100);
document.getElementById('calc1_LTV').innerHTML = c1ltv + "%";
}
}
function cltv()
{
var myDiv = document.getElementById( "tbp" );
var inputArr = myDiv.getElementsByClassName( "checkbox" );
for (var i = 0; i < inputArr.length; i++) {
if(inputArr[i].checked == false){
alert( inputArr[i].value );
}
}
}
function payOffMortgage()
{
var payoffmortgageone = "";
var payoffmortgagetwo = "";
var payoffmortgagethree = "";
if (document.getElementById('payOffMtg1Yes') != null)
{
if (document.getElementById('payOffMtg1Yes').checked == true)
{
payoffmortgageone = document.getElementById('first_pay');
payoffmortgageone.value = "Yes";
} else {
payoffmortgageone = document.getElementById('first_pay');
payoffmortgageone.value = "No";
}
}
if (document.getElementById('payOffMtg2Yes') != null)
{
if (document.getElementById('payOffMtg2Yes').checked == true)
{
payoffmortgagetwo = document.getElementById('second_pay');
payoffmortgagetwo.value = "Yes";
} else {
payoffmortgagetwo = document.getElementById('second_pay');
payoffmortgagetwo.value = "No";
}
}
if (document.getElementById('payOffMtg3Yes') != null)
{
if (document.getElementById('payOffMtg3Yes').checked == true)
{
payoffmortgageone = document.getElementById('third_pay');
payoffmortgageone.value = "Yes";
} else {
payoffmortgageone = document.getElementById('third_pay');
payoffmortgageone.value = "No";
}
}
}
// to update the calc1_Due field with the value from calc1_termDue field on change of data
function getDue()
{
var calc1_Due = document.getElementById('calc1_Due');
calc1_Due.value = document.getElementById('calc1_termDue').value;
}
//to update the month payment field (id="calc1_est_monthPayment")
function updateMonthPayment(a,n,p) {
var sCR1=String.fromCharCode(13);
var empa=document.getElementById('calc1_est_monthPayment');
var paymenta = getPaymenta(a,n,p);
empa.value = (Math.round(paymenta*100)/100) + sCR1;
}
function getPaymenta(a,n,p) {
/* Calculates the monthly payment from annual percentage
rate, term of loan in months and loan amount. **/
var acc=0;
var base = 1 + p/1200;
for (i=1;i<=n;i++)
{ acc += Math.pow(base,-i); }
return a/acc;
}
function getBiWeekly()
{
if (document.getElementById('calc1_biWeekPmt').checked == true)
{
if (document.getElementById('calc1_extraPmt') != "")
{
var ep = document.getElementById('calc1_extraPmt').value;
} else {
var ep = "0.00";
}
var tmonthPayment = document.getElementById('calc1_ttlMonthPmt').value; tmonthPayment = Number(tmonthPayment);
var bwa = document.getElementById('calc1_extraPmt_RO');
var bwaTerm = document.getElementById('calc1_ttlsTerm');
var bwaEffect = document.getElementById('calc1_effective');
bwa.value = Math.abs(ep/2+(tmonthPayment/2)).toFixed(2);
//bwaTerm
// for the effective rate and term in yrs (bi weekly)
var calc1nr = document.getElementById('calc1_noteRate').value; calc1nr = Number(calc1nr);
var calc1ttlsterm = document.getElementById('calc1_ttlsTerm').value; calc1ttlsterm = Number(calc1ttlsterm);
var effectannualrate = document.getElementById('calc1_effective');
var counter=0;
//effectannualrate.value = Math.pow(1+(calc1nr/calc1ttlsterm),(1/26)-1);
var np = calc1ttlsterm;
var ir = calc1nr;
var pmt = -1 * tmonthPayment;
var pv = document.getElementById('hv').value;
var fv = 0;
var pb = true;
function comp_ir(np,ir,pmt,pv,fv,pb)
{
var tir = ir; // default value
var maxtries = 400;
var val = 0;
var oldval = 0;
var delta = 0;
var olddelta = 0;
if((fv == 0.0) && (pv == 0.0)) {
tir = (pmt < 0)?-1.0:1.0;
}
else {
var k = 0;
var solved = false;
do {
var i = 0;
var j = 0;
var guess = (k == 0)?ir:-ir;
var gd = guess * .5;
if(gd == 0.0)
gd = 1.0;
do {
guess += gd;
if(guess != 0.0) {
val = comp_fv(np,guess,pmt,pv,pb);
delta = Math.abs(val-fv);
}
if(i > 0) { // old values not set on i == 0
j++;
//test match of absolute values and rate of change
if((Math.abs(val-oldval) > 1e-8) || (delta > 1e-8)) {
j = 0;
}
if(delta > olddelta) {
gd *= -.5;
}
}
oldval = val;
olddelta = delta;
}
while((i++ < maxtries) && (j < 3));
if(i < maxtries) {
tir = guess;
solved = true;
}
}
while((k++ < 2) && !solved);
if(!solved) {
alert("Cannot compute interest for these values.");
}
}
return tir;
document.write(tir);
}
} else {
var effectannualrate = document.getElementById('calc1_effective');
var bwa = document.getElementById('calc1_extraPmt_RO');
bwa.value = "0.00";
effectannualrate.value = "0%";
}
}
function get_biWeekly_Amortization(a,n,p) {
var i=0;
var sATline1="";
var oAmortizationTable2=document.getElementById("amortizationtable");
oAmortizationTable2.style.visibility="visible";
var sCR1=String.fromCharCode(13);
var sTab1=String.fromCharCode(27);
var extra=document.getElementById('calc1_extraPmt_RO').value; extra = Number(extra);
/* calculate amortization and write modified values to the amortization table */
var payment1 = getPayment1(a,n,p);
oAmortizationTable2.value = sCR1 + "Monthly Payment = " + (Math.round(extra*100)/100) + sCR1 + sCR1;
oAmortizationTable2.value += "Month Balance Principal Interest Payment Total Interest" + sCR1;
var balance1=a;
var interest1 = 0.0;
var principal1 = 0.0;
var totalinterest1 = 0.0;
for (i=1;i<=n;i++) {
interest1 = balance1*extra/1200;
totalinterest1 += interest1;
principal1 = extra-interest1;
balance1 -= principal1;
sATline1 = i.toString()+getSpaces1(7-i.toString().length);
sATline1 += (Math.round(balance1*100)/100);
sATline1 += getSpaces(18-sATline1.length);
sATline1 += (Math.round(principal1*100)/100);
sATline1 += getSpaces(29-sATline1.length);
sATline1 += (Math.round(interest1*100)/100);
sATline1 += getSpaces(39-sATline1.length);
sATline1 += (Math.round(i*extra*100)/100);
sATline1 += getSpaces(50-sATline1.length);
sATline1 += (Math.round(totalinterest1*100)/100) + sCR1;
oAmortizationTable2.value += sATline1;
}
}
function getSpaces1(n) {
var i=0;
var sSpaces="";
for (i=0;i<n;i++) {sSpaces += " ";}
return sSpaces;
}
function getPayment1(a,n,p) {
/* Calculates the monthly payment from annual percentage
rate, term of loan in months and loan amount. **/
var acc=0;
var base = 1 + document.getElementById('calc1_extraPmt_RO').value/1200;
for (i=1;i<=n;i++)
{ acc += Math.pow(base,-i); }
return a/acc;
}
here is the php/xhtml that the script interacts with:
<div id="s1">
<fieldset id="nestedS1">
<script type="text/javascript">
document.observe('dom:loaded',function(){
new Control.Tabs('amort_tabs',{
linkSelector: 'li.tabAmort a'
});
});
</script>
<legend>Scenario 1</legend>
<input type="hidden" name="gi" id="gi" value="<?php if(isset($GI)) { echo $GI; } ?>" />
<input type="hidden" name="hv" id="hv" value="<?php if(isset($HV)) { echo $HV; } ?>" />
<input type="hidden" name="bh" id="bh" />
<input type="hidden" name="mtghidden" id="mtghidden" />
<input type="hidden" name="first_pay" id="first_pay" />
<input type="hidden" name="second_pay" id="second_pay" />
<input type="hidden" name="third_pay" id="third_pay" />
<input type="hidden" name="EscrowAmt" id="EscrowAmt" />
<table summary="calculator 1" class="borderLess" id="amortizationTableT">
<tr>
<td colspan="2">
<!-- table loanType select -->
<table summary="loan types">
<!--caption>Loan Type</caption-->
<tr>
<td>
<label for="scenerio1LoanType">Loan Type</label>
<select name="scenerio1LoanType" id="scenerio1LoanType">
<?php if($scenerio1LoanType != "") { ?>
<option selected="selected" value="<?php echo $scenerio1LoanType; ?>"><?php echo $scenerio1LoanType; ?></option>
<optgroup label="Update">
<option value="Conventional">Conventional</option>
<option value="FHA">FHA</option>
<option value="VA">VA</option>
<option value="USDA">USDA</option>
<option value="Reverse">Reverse</option>
<option value="HELOC">HELOC</option>
<option value="Other">Other</option>
</optgroup>
<?php } else { ?>
<option value="Conventional">Conventional</option>
<option value="FHA">FHA</option>
<option value="VA">VA</option>
<option value="USDA">USDA</option>
<option value="Reverse">Reverse</option>
<option value="HELOC">HELOC</option>
<option value="Other">Other</option>
<?php } ?>
</select>
</td>
<td>
<label for="scenerio1LienPosition">Lien Position</label>
<select name="scenerio1LienPosition" id="scenerio1LienPosition">
<?php if($scenerio1LienPosition != "" ) { ?>
<option selected="selected" value="<?php echo $scenerio1LienPosition; ?>"><?php echo $scenerio1LienPosition; ?></option>
<optgroup label="Update">
<option value="First Mtg">First Mtg.</option>
<option value="Second Mtg">Second Mtg.</option>
</optgroup>
<?php } else { ?>
<option value="First Mtg">First Mtg.</option>
<option value="Second Mtg">Second Mtg.</option>
<?php } ?>
</select>
</td>
<td>
<label for="scenerio1Purpose">Purpose</label>
<select name="scenerio1Purpose" id="scenerio1Purpose">
<?php if($scenerio1Purpose != "" ) { ?>
<option selected="selected" value="<?php echo $scenerio1Purpose; ?>"><?php echo $scenerio1Purpose; ?></option>
<optgroup label="Update">
<option value="Purchase">Purchase</option>
<option value="cashOutRefi">Cash-out Refi</option>
<option value="noCashOutRefi">No Cash-out Refi</option>
<option value="Other">Other</option>
</optgroup>
<?php } else { ?>
<option value="Purchase">Purchase</option>
<option value="cashOutRefi">Cash-out Refi</option>
<option value="noCashOutRefi">No Cash-out Refi</option>
<option value="Other">Other</option>
<?php } ?>
</select>
</td>
</tr>
</table>
<!-- END:table loanType select -->
</td>
</tr>
<tr>
<td style="width:48%;">
<table summary="">
<tr>
<td align="right"><label for="calc1_pp">Purchase Price: <span class="dollarSign">($)</span></label></td>
<td>
<input type="text" name="calc1_pp" id="calc1_pp" onchange="tbpOffTtl()"
value="<?php if(isset($calc1_pp)) { echo $calc1_pp; } ?>" /></td>
</tr>
<tr>
<td align="right"><label for="calc1_loanAmount">Loan Amount: <span class="dollarSign">($)</span></label></td>
<td>
<input type="text" name="calc1_loanAmount" id="calc1_loanAmount"
value="<?php if(isset($calc1_loanAmount)) { echo $calc1_loanAmount; } ?>" onchange="updateMonthPayment(document.getElementById('calc1_loanAmount').value,
document.getElementById('calc1_termDue').value,
document.getElementById('calc1_noteRate').value)" /></td>
</tr>
<tr>
<td align="right"><label for="calc1_refi">Refinance: <span class="dollarSign">($)</span><br /> <span class="subNote">(incl. debts to be paid off)</span></label></td>
<td>
<input type="text" name="calc1_refi" id="calc1_refi"
value="<?php if(isset($calc1_refi)) { echo $calc1_refi; } ?>" /></td>
</tr>
<tr>
<td align="right"><label for="calc1_preItems">Pre-paid Items: <span class="dollarSign">($)</span></label></td>
<td>
<input type="text" name="calc1_preItems" id="calc1_preItems"
value="<?php if(isset($calc1_preItems)) { echo $calc1_preItems; } ?>" /></td>
</tr>
<tr>
<td align="right"><label for="calc1_closeCost">Closing Cost: <span class="dollarSign">($)</span></label></td>
<td>
<input type="text" name="calc1_closeCost" id="calc1_closeCost"
value="<?php if(isset($calc1_closeCost)) { echo $calc1_closeCost; } ?>" /></td>
</tr>
<tr>
<td align="right">
<label for="calc1_fundingFee">MIP, Funding Fee: <span class="dollarSign">($)</span></label></td>
<td>
<input type="text" name="calc1_fundingFee" id="calc1_fundingFee"
value="<?php if(isset($calc1_fundingFee)) { echo $calc1_fundingFee; } ?>" />
</td>
</tr>
<tr>
<td align="right"><label for="calc1_cash">Cash from/to Borrower: <span class="dollarSign">($)</span></label></td>
<td>
<input type="text" name="calc1_cash" id="calc1_cash"
value="<?php if(isset($calc1_cash)) { echo $calc1_cash; } ?>" readonly="readonly" /></td>
</tr>
<tr>
<td align="right"><label for="calc1_noteRate">Note Rate: </label></td>
<td>
<input type="text" name="calc1_noteRate" id="calc1_noteRate"
value="<?php if(isset($calc1_noteRate)) { echo $calc1_noteRate; } ?>" onchange="updateMonthPayment(document.getElementById('calc1_loanAmount').value,
document.getElementById('calc1_termDue').value,
document.getElementById('calc1_noteRate').value)" />
<span class="dollarSign">%</span>
</td>
</tr>
<tr>
<td align="right"><label for="calc1_termDue">Term/Due: </label></td>
<td><input type="text" id="calc1_termDue" name="calc1_termDue"
value="<?php if(isset($calc1_termDue)) { echo $calc1_termDue; } ?>" onchange="getAmortization(document.getElementById('calc1_loanAmount').value,
document.getElementById('calc1_termDue').value,
document.getElementById('calc1_noteRate').value)" onBlur="getDue()" /> /
<label for="calc1_Due" style="display: none;"> </label>
<input type="text" name="calc1_Due" id="calc1_Due"
value="<?php if(isset($calc1_Due)) { echo $calc1_Due; } ?>" readonly="readonly" /></td>
</tr>
<tr>
<td align="right">
<label for="calc1_est_monthPayment">Month Payment: <span class="dollarSign">($)</span></label>
</td>
<td>
<input type="text" readonly="readonly" name="calc1_est_monthPayment" id="calc1_est_monthPayment"
value="<?php if(isset($calc1_est_monthPayment)) { echo $calc1_est_monthPayment; } ?>" onBlur="tmp()" />
</td>
</tr>
<tr>
<td align="right">
<label for="calc1_IO">I/O </label>
</td>
<td align="left">
<input type="checkbox" class="checkbox" name="calc1_IO" id="calc1_IO"
value="<?php if(isset($calc1_IO)) { echo $calc1_IO; } ?>" />
</td>
</tr>
<tr>
<td align="right"><label for="calc1_hazardIns">Haz. Insurance: <span class="dollarSign">($)</span></label></td>
<td>
<input type="text" name="calc1_hazardIns" id="calc1_hazardIns" size="6"
value="<?php if(isset($calc1_hazardIns)) { echo $calc1_hazardIns; } ?>" onBlur="tmp()"/></td>
</tr>
<tr>
<td align="right"><label for="calc1_taxes">Taxes: <span class="dollarSign">($)</span></label></td>
<td>
<input type="text" name="calc1_taxes" id="calc1_taxes" size="6"
value="<?php if(isset($calc1_taxes)) { echo $calc1_taxes; } ?>" onBlur="tmp()" />
</td>
</tr>
<tr>
<td align="right"><label for="calc1_MIP">MI: <span class="dollarSign">($)</span></label></td>
<td>
<input type="text" name="calc1_MIP" id="calc1_MIP"
value="<?php if(isset($calc1_MIP)) { echo $calc1_MIP; } ?>" size="6" onBlur="tmp()" />
</td>
</tr>
<tr>
<td align="right"><label for="calc1_HOADues">HOA Dues: <span class="dollarSign">($)</span></label></td>
<td>
<input type="text" name="calc1_HOADues" id="calc1_HOADues"
value="<?php if(isset($calc1_HOADues)) { echo $calc1_HOADues; } ?>" size="6" onBlur="tmp()" />
</td>
</tr>
<tr>
<td align="right"><label for="calc1_ttlMonthPmt">Ttl Mnth Pmt: <span class="dollarSign">($)</span></label> </td>
<td>
<input type="text" name="calc1_ttlMonthPmt" id="calc1_ttlMonthPmt" size="6"
value="<?php if(isset($calc1_ttlMonthPmt)) { echo $calc1_ttlMonthPmt; } ?>" readonly="readonly" />
</td>
</tr>
<tr>
<td align="right"><label for="calc1_ttlSavings">Total Savings: <span class="dollarSign">($)</span></label></td>
<td>
<input type="text" name="calc1_ttlSavings" id="calc1_ttlSavings"
value="<?php if(isset($calc1_ttlSavings)) { echo $calc1_ttlSavings; } ?>" size="4" readonly="readonly" /></td>
</tr>
<tr>
<td align="right">
<label for="calc1_extraPmt">Extra Payment of: <span class="dollarSign">($)</span></label>
</td>
<td>
<input type="text" size="6" name="calc1_extraPmt" id="calc1_extraPmt"
value="<?php if(isset($calc1_extraPmt)) { echo $calc1_extraPmt; } ?>" />
</td>
</tr>
<tr>
<td align="right">
<label for="calc1_biWeekPmt">Bi-weekly Payment? </label>
</td>
<td>
<?php
if($calc1_biWeekPmt == 'Yes') {
echo '<input type="checkbox" class="checkbox" name="calc1_biWeekPmt" id="calc1_biWeekPmt" onclick="getBiWeekly()" value="Yes" checked="checked"/>';
} else {
echo '<input type="checkbox" class="checkbox" name="calc1_biWeekPmt" id="calc1_biWeekPmt" onclick="getBiWeekly()" value="Yes"/>';
}
?>
</td>
</tr>
<tr>
<td align="right">
<label for="calc1_extraPmt_RO">Bi-weekly Amount: <span class="dollarSign">($)</span></label>
</td>
<td>
<input type="text" name="calc1_extraPmt_RO" id="calc1_extraPmt_RO"
value="<?php if(isset($calc1_extraPmt_RO)) { echo $calc1_extraPmt_RO; } ?>" readonly="readonly" size="6" />
</td>
</tr>
<tr>
<td align="right"><label for="calc1_ttlsTerm">Term: </label></td>
<td>
<input type="text" readonly="readonly" size="6" name="calc1_ttlsTerm"
value="<?php if(isset($calc1_ttlsTerm)) { echo $calc1_ttlsTerm; } ?>" id="calc1_ttlsTerm"/></td>
</tr>
<tr>
<td align="right"><label for="calc1_effective">Effective: </label></td>
<td>
<input type="text" readonly="readonly" name="calc1_effective"
value="<?php if(isset($calc1_effective)) { echo $calc1_effective; } ?>" id="calc1_effective" />
<span class="dollarSign">%</span>
</td>
</tr>
</table>
</td>
<td valign="top">
<table>
<tr>
<td>
<label for="calc1_top"><span class="u">Top</span></label>
</td>
<td> <span class="dollarSign"> % </span>
<input type="text" readonly="readonly" size="5" name="calc1_top" id="calc1_top"
value="<?php if(isset($calc1_top)) { echo $calc1_top; } ?>" />
<input type="button" value="Get Top" onclick="top();" />
</td>
</tr>
<tr>
<td>
<label for="calc1_Bottom"><span class="u">Bottom</span></label>
</td>
<td> <span class="dollarSign"> % </span>
<input type="text" readonly="readonly" size="5" name="calc1_Bottom" id="calc1_Bottom"
value="<?php if(isset($calc1_Bottom)) { echo $calc1_Bottom; } ?>" />
<input type="button" value="Get Bottom" onclick="totalNotPayOff();" disabled="true" />
</td>
</tr>
<tr>
<td>
<label for="calc1_LTV"><span class="u">LTV</span></label>
</td>
<td> <span class="dollarSign"> % </span>
<input type="text" readonly="readonly" size="5" name="calc1_LTV" id="calc1_LTV"
value="<?php if(isset($calc1_LTV)) { echo $calc1_LTV; } ?>" />
<input type="button" value="Get LTV" onclick="ltv();" />
</td>
</tr>
<tr>
<td>
<label for="calc1_CLTV"><span class="u">CLTV</span></label>
</td>
<td> <span class="dollarSign"> % </span>
<input type="text" readonly="readonly" size="5" name="calc1_CLTV" id="calc1_CLTV"
value="<?php if(isset($calc1_CLTV)) { echo $calc1_CLTV; } ?>" />
<input type="button" value="Get CLTV" onclick="cltv();" disabled="true" />
</td>
</tr>
</table>
<table id="tbpTable">
<caption>To Be Paid</caption>
<tr>
<td align="left">
<div id="tbp"><?php include $_SERVER['DOCUMENT_ROOT']."/prosperAlpha/app/content/payoffList.php"; ?></div>
<!-- add code here for dynamically building input fields for each and only each to be paid Item -->
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
<div class="loan">
<div class="loan_out" style="display:none;" id="det"><?php include $_SERVER['DOCUMENT_ROOT']."/prosperAlpha/app/content/tmpBWCalc.html"; ?></div>
</div>
</td>
</tr>
<!--tr>
<td colspan="2">
<p>
<textarea id="amortizationtable" rows="16" cols="58" wrap="off" style="display:none;visibility:hidden;background-color:silver">
</textarea>
</p>
</td>
</tr-->
</table>
<!--input type="button"
name="calculateScen1"
value="Calculate"
onclick="getAmortization(document.getElementById('calc1_loanAmount').value,
document.getElementById('calc1_termDue').value,
document.getElementById('calc1_noteRate').value)" disabled="disabled" /-->
<input type="reset" value="Revert to Last Saved" />
<!--input type="button" value=" Amortization Table " /-->
<!--input type="button" class="submit" onclick="showBox_am1()" onfocus="getAmortization(document.getElementById('calc1_loanAmount').value,
document.getElementById('calc1_termDue').value,
document.getElementById('calc1_noteRate').value)" title="Amortization Schedule Scenario 1" value="View Amortization Schedule" /-->
<input type="button" class="submit" name="tmp" id="tmp" onclick='javascript:gmyWin=myOpenWindow("includes/phpLoanCalc/loan-calculator.php?loan_amount=<?php echo $calc1_loanAmount; ?>&loan_length=<?php echo $first_term; ?>&annual_interest=<?php echo $calc1_noteRate; ?>&calc1_taxes=<?php echo $calc1_taxes; ?>&calc1_MIP=<?php echo $calc1_MIP; ?>&ep=<?php echo $calc1_extraPmt; ?>", "testing", "height=500,width=425px,scrollbars=yes", gmyWin ); return false' value="Amoritize" />
<!-- END:calc1 table -->
</fieldset>
</div><!-- eEND: s1 -->
<div id="am1Box" style="display:none">
<img id="close" src="../app/images/close.gif" onclick="hideBox_am1()" alt="Close" title="Close this window" />
<div id="container_am1">
<?php
//include ('amortSched1.block.php');
//include ($_SERVER['DOCUMENT_ROOT'].'/prosperAlpha/app/includes/phpLoanCalc/loan-calculator.php');
?>
</div>
</div>