Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Mortgage/Rent calculator

1. ## Mortgage/Rent calculator

Help on Javascript

I’m trying to write a simple javascript form that calculates a figure based on two inputed values. The basis of this form is that we have 3 pay rate at 5.15, 5.24 and 5.49 and three max loan to value rates of 65%, 75% and 85%. The user inputs his property value and current rent and presses submit, then the form calculates the maximum potential loan available and the monthly payments needed. The maximum loan is calculated with the forumula

Rent Per Month * 12/ 1.25 / pay rate * 100

The catch is the max potential loan can not be more than the max loan to value rates (i.e 65%, 75% and 85%). This what I’ve got so far.

<html>

<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>LTV</title>
<SCRIPT LANGUAGE="JavaScript">
function evalmax ()
{
// Tidy-up input values
var CurRent = parseInt(document.evalform.currentRent.value);
var CurVal = parseInt(document.evalform.propVal.value);

// Loan to value rate
var lToValue65 = 0.65; //This is 65%
var lToValue75 = 0.75; //This is 75%
var lToValue85 = 0.85; //This is 85%

// Baserate
var baseRate = 0.045; //This is the base rate at 4.5%

// Plus margin
var plusMargin65 = 0.0065; //This is 0.65%
var plusMargin75 = 0.0074; //This is 0.74%
var plusMargin85 = 0.0099; //This is 0.99%

var payRate65 = plusMargin65 + baseRate; //This calculates the total payrate for 65% LTV
var payRate75 = plusMargin75 + baseRate; //This calculates the total payrate for 75% LTV
var payRate85 = plusMargin85 + baseRate; //This calculates the total payrate for 85% LTV

var maxMortgage65 = Math.ceil(CurRent * 12 / 1.25 / payRate65 * 100);
var maxMortgage75 = Math.ceil(CurRent * 12 / 1.25 / payRate75 * 100);
var maxMortgage85 = Math.ceil(CurRent * 12 / 1.25 / payRate85 * 100);

document.evalform.prop65.value = maxMortgage65;
document.evalform.prop75.value = maxMortgage75;
document.evalform.prop85.value = maxMortgage85;

var calcRent65 = Math.ceil(payRate65*CurRent);
var calcRent75 = Math.ceil(payRate75*CurRent);
var calcRent85 = Math.ceil(payRate85*CurRent);

document.evalform.rent65.value = calcRent65;
document.evalform.rent75.value = calcRent75;
document.evalform.rent85.value = calcRent85;
}
</SCRIPT>
</head>

<body>

<FORM NAME="evalform">
<p><b><font face="Verdana">Property value: £</font></b>
<font face="Verdana, Arial, Helvetica, sans-serif" size="3">
<B><INPUT NAME="propVal" TYPE="text" SIZE=12><br>Rent per month: £
<INPUT NAME="currentRent" TYPE="text" SIZE=12></B>
</font>
<INPUT NAME="button" TYPE="button" VALUE="Submit" OnClick="evalmax()" style="float: left"></p>
<p align="left"> </p>

<table border="0" width="40%" id="table1">
<tr>
<td>LTV</td>
<td>Property value</td>
<td>Rent per month</td>
</tr>
<tr>
<td>65% LTV</td>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="3">
<B>£<INPUT NAME="prop65" TYPE="text" SIZE=12></B></font></td>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="3">
<B>£<INPUT NAME="rent65" TYPE="text" SIZE=12></B></font></td>
</tr>
<tr>
<td>75% LTV</td>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="3">
<B>£<INPUT NAME="prop75" TYPE="text" SIZE=12></B></font></td>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="3">
<B>£<INPUT NAME="rent75" TYPE="text" SIZE=12></B></font></td>
</tr>
<tr>
<td>85% LTV</td>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="3">
<B>£<INPUT NAME="prop85" TYPE="text" SIZE=12></B></font></td>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="3">
<B>£<INPUT NAME="rent85" TYPE="text" SIZE=12></B></font></td>
</tr>
</table>
<p> </p>

</FORM>

</body>

</html>
First problem: This forumula does not work correctly

var maxMortgage65 = Math.ceil(CurRent * 12 / 1.25 / payRate65 * 100);

And neither do the two below it, in excel it's this forumla "=E15*12/1.25/5.15*100" (where E15 is 700 and the answer is 112000). Any help on that appriciated as the javascript is not giving me the correct answer.

Secondly. The 3 property value boxes at the bottom should never exceed 65, 75 or 85% of the value the inputed property value. I was thinking of using a series of IF statements that would say something along the line of if value is less that 65% of property, then display it, if value is equal or greater then just display 65% of property value. Is this the best way or is there a more elegant solution?

BTW: This is my first ever expirence using java script but I do know Java and C#.

• I have written this to try and answer my bottom question but it doesn't seem to make any difference

if (maxMortgage65<(0.65*CurVal))
{
maxMortgage65 = maxMortgage65;
}
else
{
maxMortage65 = 0.65*CurVal;
}

if (maxMortgage75<(0.75*CurVal))
{
maxMortgage75 = maxMortgage75;
}
else
{
maxMortgage75 = 0.75*CurVal;
}

if (maxMortgage85<(0.85*CurVal))
{
maxMortgage85 = maxMortgage85;
}
else
{
maxMortgage85 = 0.85*CurVal;
}

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•