This calculator helps you estimate how much you might be able to borrow for a mortgage based on your income, debts, and a desired down payment. It's important to remember that this is an estimation tool. Lenders will have their own specific criteria and will perform a full credit assessment.
Your Estimated Maximum Mortgage Amount:
$0
Disclaimer: This is an estimate and does not represent a loan offer. Lender approval depends on various factors including credit score, debt-to-income ratio, and property appraisal.
function calculateMortgageAffordability() {
var annualIncome = parseFloat(document.getElementById("annualIncome").value);
var monthlyDebtPayments = parseFloat(document.getElementById("monthlyDebtPayments").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var interestRate = parseFloat(document.getElementById("interestRate").value);
var loanTermYears = parseFloat(document.getElementById("loanTermYears").value);
var resultElement = document.getElementById("maxMortgageAmount");
if (isNaN(annualIncome) || annualIncome <= 0 ||
isNaN(monthlyDebtPayments) || monthlyDebtPayments < 0 ||
isNaN(downPayment) || downPayment < 0 ||
isNaN(interestRate) || interestRate <= 0 ||
isNaN(loanTermYears) || loanTermYears <= 0) {
resultElement.textContent = "Please enter valid numbers for all fields.";
return;
}
// General guideline: Lenders often use a Debt-to-Income (DTI) ratio.
// A common guideline is that total housing costs (PITI) should not exceed 28% of gross monthly income,
// and total debt payments (including housing) should not exceed 36% of gross monthly income.
// We'll use the 36% rule for total debt to estimate the maximum monthly payment allowed.
var grossMonthlyIncome = annualIncome / 12;
var maxTotalMonthlyDebtPayment = grossMonthlyIncome * 0.36;
var maxAllowedMonthlyMortgagePayment = maxTotalMonthlyDebtPayment – monthlyDebtPayments;
if (maxAllowedMonthlyMortgagePayment <= 0) {
resultElement.textContent = "$0 (Your current debts may be too high for additional mortgage payments based on this income).";
return;
}
// Now, calculate the maximum loan amount based on the maxAllowedMonthlyMortgagePayment.
// The formula for a mortgage payment (M) is: M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
// Where:
// P = Principal loan amount (what we want to find)
// i = monthly interest rate (annual rate / 12)
// n = total number of payments (loan term in years * 12)
var monthlyInterestRate = (interestRate / 100) / 12;
var numberOfPayments = loanTermYears * 12;
if (monthlyInterestRate <= 0 || numberOfPayments <= 0) {
resultElement.textContent = "Invalid interest rate or loan term for calculation.";
return;
}
// Rearrange the formula to solve for P:
// P = M * [ (1 + i)^n – 1] / [ i(1 + i)^n ]
var numerator = Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1;
var denominator = monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments);
var maxLoanPrincipal = maxAllowedMonthlyMortgagePayment * (numerator / denominator);
// The maximum mortgage *amount* is the loan principal plus the down payment.
// However, this calculator is typically for estimating how much you can *borrow*.
// So we will display the maximum loan principal.
resultElement.textContent = "$" + maxLoanPrincipal.toFixed(2);
}
#mortgage-calculator {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
#mortgage-calculator h2, #mortgage-calculator h3 {
text-align: center;
color: #333;
}
#mortgage-calculator p {
text-align: justify;
color: #555;
margin-bottom: 15px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.form-group input[type="number"] {
width: calc(100% – 20px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
#mortgage-calculator button {
display: block;
width: 100%;
padding: 10px 15px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 20px;
}
#mortgage-calculator button:hover {
background-color: #0056b3;
}
#result {
margin-top: 25px;
padding: 15px;
border-top: 1px solid #eee;
text-align: center;
}
#result h3 {
margin-bottom: 10px;
color: #007bff;
}
#maxMortgageAmount {
font-size: 24px;
font-weight: bold;
color: #333;
}
#result p strong {
color: #d9534f;
}