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: Maximum loan amount calculation

1. ## Maximum loan amount calculation

Hi guys

I'm hoping someone out there can help me.

I need a script/function that works in "classic asp" that will allow me to display the maximum loan amount a user can borrow based on:

1. The monthly payment they can afford
2. The interest rate charged by the lender
3. The number of months the loan will be paid over

In practical terms, I need to know the total loan amount available. For example, if someone can afford to pay back the lender £200 per month at a rate of 5.5% over the period of 36 months then how much can they borrow?

Ideally, I would just add in the values (200, 5.5, 36) into my function and my page would simply display the maximum loan amount.

I have tried to find a solution for the best part of two weeks and it's driving me mad.

Any help would be fully appreciated

Best regards

Rod from the UK

https://www.moneyhero.com.hk/blog/en...unt-calculated

Once you’ve obtained the figures for your monthly income, loan tenor, and monthly interest rate (or annual interest rate divided by 12), you can start doing rough calculations for the largest possible amount you can borrow from your bank. Your monthly interest (expressed in decimal form) is R, your loan tenor (expressed in months) is M, and the payment from your monthly income is P. The formula for calculating your maximum loan principal would look something like this:

Maximum Loan Amount = P/R * {1 – [1 / (1+R)^M] }

3. Hi Josephm

How do I apply this formula within asp code? This is my problem really.

Any help would be fully appreciated

Best regards

Rod from the UK

4. The question is what do you want to do. Do you want the user to have a tool to calculate the amount? What do you want to do with the amount calculated. Do you just want to present the amount or do you want to save the amount calculated in a file/database.

If you just want to present the amount, the simplest approach is to make a javascript function.

As an example: (not tested)

Code:
```<!DOCTYPE html>
<html>
<body>

Monthly repayments: <input type="text" name="mrepayments" id="mrepayments" /><br>
Interest Rate: <input type="text" name="iRate" id="iRate" /><br>
Number of months:  <input type="text" name="noofmonths" id="noofmonths" /><br>

Maximum amount : <p id="maxamt"></p>

<input type="button" onclick="Calculate();" value="Calculate!" />

<script>
function Calculate() {
var mrep = parseFloat(document.getElementById("mrepayments").value);
var irate = parseFloat(document.getElementById("iRate").value);
var nmonths = parseFloat(document.getElementById("noofmonths").value);

var maxamt = do you calculation here;

document.getElementById("maxamt").innerHTML = maxamt;
}
</script>

</body>
</html>```
Of course, in practice, you'll have to validate the inputs and show errors.

If you need to do the calculation in the server, same html except you'll have to wrap the inputs inside a <form> and send the data to the server.

5. Hi Josephm

Thank you so much for my reply, I really appreciate it.

I'm probably not explaining myself too well unfortunately.

Basically, I have a car classifieds website (classic asp). What I'm looking to so is have two ways in which my users can search for a car. They can search for cars under a budget (eg £10000) or they can search for cars based on what they can afford each month (eg £150).

The conventional search works fine. However, I need to create the search form that allows users to search by monthly payment. The idea is that my user can select an amount they can afford each month (eg £150) this then populates a hidden "price" field contained within the form. A much simplified version of my form can be seen below.

<form method=post action=searchresults.asp>
<input type="text" name="make"/>
<input type="text" name="model"/>
<select name="monthlybudget">
<option value="50">£50</option>
<option value="100">£100</option>
<option value="150">£150</option>
<option value="200">£200</option>
<option value="250">£250</option>
</select>

<input type="hidden" name="carprice"/>

<input type="submit" value="Search">
</form>

Ideally, the user would select their monthly budget and the hidden "carprice" field would populate with the maximum loan amount based on the monthly payment and the annual interest rate. The user would then click on "Search" and my search results page would do the rest in terms of finding cars cheaper than the hidden "carprice" value.

This is my first problem. I then need to pretty much do the reverse on my search results page. So, if it's showing a car that costs £10,000, then there's a function in my page that works out the monthly payment again based on a set interest rate and loan month term.

What I am trying to do is best seen on tis website: Carcraft.co.uk | Over 100,000 Used Cars For Sale. You'll see that you can search their cars by monthly payment. Their results page shows the car price and the monthly payment based on a representative rate and term.

Is this possible? Again any help would be fully appreciated.

PS: Unfortunately, your code did not work

I look forward to hearing from you

Best regards

Rod from the UK

6. This is what base on what I understand you want to achieve.

driver.asp

There is no need for a hidden field as all computations will be done by searcresult.asp. I left it intact in case I misunderstood what you want to do.
Also I added a field 'nomonths' that is the duration of the loan

Code:
```<!DOCTYPE html>
<html>
<body>

<form  method=post action=searchresults.asp>
<label>make&nbsp</label><input type="text" name="make" id="make"/><br />
<label>model&nbsp</label><input type="text" name="model" id="model" /><br />
<label>monthly budget&nbsp</label>
<select name="monthlybudget" id="monthlybudget" >
<option value="50">£50</option>
<option value="100">£100</option>
<option value="150">£150</option>
<option value="200">£200</option>
<option value="250">£250</option>
</select>
<br />

<label>no of months&nbsp</label><input type="text" name="nomonths" id="nomonths" /><br />

<input type="hidden" name="carprice" id="carprice" />

<input type="submit" value="Search" name="xsubmit" id="xsubmit" onclick="return Validate();" />
</form>
<span id="errors"></span>

<script>
function Validate() {
var emsg = "";
var dmake = document.getElementById("make").value;
if (dmake == "") {
emsg += "please specify make<br />";
}

var dmodel = document.getElementById("model").value;
if (dmodel == "") {
emsg += "please specify make<br />";
}

var dmonths = document.getElementById("nomonths").value;
if (dmonths == "") {
emsg += "please specify no of months<br />";
}
else {
if (isNaN(dmonths)) {
emsg += "number of monnths must be numeric<br />";
}
}
if (emsg != "") {
document.getElementById("errors").innerHTML = emsg;
return false;
}

return true;
}
</script>
</body>
</html>```
searchresults.asp

Code:
```<!DOCTYPE html>
<html>
<body>
<%
Dim make
Dim	model
Dim budget
Dim noMonths
Dim iRate
Dim maxLoan

make = ""
model = ""
budget = 0
noMonths = 0
iRate = 15
maxLoan = 0

response.write("Contents of form<br />")
If Request.Form <> "" Then
response.write(Request.Form & "<br /><br />")
response.write("make " & Request.Form("make") & "<br />")
response.write("model " & Request.Form("model") & "<br />")
response.write("monthlybudget " & Request.Form("monthlybudget") & "<br />")
response.write("nomonths" & Request.Form("nomonths") & "<br />")
response.write("xsumbit " & Request.Form("xsubmit") & "<br />")
If Request.Form("xsubmit") = "Search"  Then
response.write("Is submit")
make = Request.Form("make")
model = Request.Form("model")
budget = Request.Form("monthlybudget")
noMonths = Request.Form("nomonths")
' validate the parameter passed.
' make must be specified?
' model must be stecified
' monthly budget must be specified and numeric
' no of months must be specified and numeric
' if validation failed, abort the processing
budget = CDbl(budget)
nomonths = CDbl(nomonths)

' a dummy routine to get the maximum loan amount. use your own formula

maxLoan = budget * nomonths
maxLoan = maxLoan - (maxLoad * (IRate / 100))

End If
End If
%>

<h2>Maximum loan = <% response.write(maxLoan) %></h2>

</body>
</html>```
There is no guaranty that the data given to searchresults.asp is valid. You'll have to validate the data again.

7. In practice, you'll have to validate the inputs and show errors.