This calculator helps you estimate how much you can afford to borrow for a mortgage based on your income, debts, and desired monthly payment. It's important to remember that this is an estimation tool. Lenders will consider many other factors when approving your loan, including your credit score, down payment, employment history, and the specific property you wish to purchase.
function calculateMortgageAffordability() {
var annualIncome = parseFloat(document.getElementById("annualIncome").value);
var monthlyDebt = parseFloat(document.getElementById("monthlyDebt").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var interestRate = parseFloat(document.getElementById("interestRate").value) / 100;
var loanTermYears = parseInt(document.getElementById("loanTermYears").value);
var maxPITIPercentage = parseFloat(document.getElementById("maxPITI").value) / 100;
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
// Input validation
if (isNaN(annualIncome) || annualIncome <= 0) {
resultDiv.innerHTML = "Please enter a valid annual household income.";
return;
}
if (isNaN(monthlyDebt) || monthlyDebt < 0) {
resultDiv.innerHTML = "Please enter valid total monthly debt payments.";
return;
}
if (isNaN(downPayment) || downPayment < 0) {
resultDiv.innerHTML = "Please enter a valid down payment amount.";
return;
}
if (isNaN(interestRate) || interestRate <= 0) {
resultDiv.innerHTML = "Please enter a valid annual interest rate.";
return;
}
if (isNaN(loanTermYears) || loanTermYears <= 0) {
resultDiv.innerHTML = "Please enter a valid loan term in years.";
return;
}
if (isNaN(maxPITIPercentage) || maxPITIPercentage 1) {
resultDiv.innerHTML = "Please enter a maximum PITI percentage between 1 and 100.";
return;
}
var monthlyIncome = annualIncome / 12;
var maxMonthlyPITI = monthlyIncome * maxPITIPercentage;
var maxMonthlyPayment = maxMonthlyPITI – monthlyDebt;
if (maxMonthlyPayment 0) {
maxLoanAmount = maxMonthlyPayment * (1 – Math.pow(1 + monthlyInterestRate, -numberOfPayments)) / monthlyInterestRate;
} else {
// Handle 0 interest rate case (though unlikely for mortgages)
maxLoanAmount = maxMonthlyPayment * numberOfPayments;
}
var affordableHomePrice = maxLoanAmount + downPayment;
// Display results
resultDiv.innerHTML =
"