Mortgage Affordability Calculator
Understanding how much mortgage you can afford is a crucial step in the home-buying process. This calculator helps you estimate your maximum affordable mortgage amount based on your income, debts, and estimated interest rates. It's important to remember that this is an estimation, and your actual loan approval will depend on a lender's specific criteria, including your credit score, down payment, and the property's appraisal.
#mortgageCalculator {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
#mortgageCalculator h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.calculator-inputs {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
margin-bottom: 20px;
}
.form-group {
display: flex;
flex-direction: column;
}
.form-group label {
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.form-group input {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
button {
grid-column: 1 / -1;
padding: 12px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #45a049;
}
.calculator-result {
margin-top: 20px;
padding: 15px;
border-top: 1px solid #eee;
text-align: center;
font-size: 18px;
font-weight: bold;
color: #333;
}
.calculator-result span {
color: #4CAF50;
}
function calculateMortgageAffordability() {
var grossMonthlyIncome = parseFloat(document.getElementById("grossMonthlyIncome").value);
var currentMonthlyDebts = parseFloat(document.getElementById("currentMonthlyDebts").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var interestRate = parseFloat(document.getElementById("interestRate").value);
var loanTerm = parseFloat(document.getElementById("loanTerm").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(grossMonthlyIncome) || grossMonthlyIncome <= 0 ||
isNaN(currentMonthlyDebts) || currentMonthlyDebts < 0 ||
isNaN(downPayment) || downPayment < 0 ||
isNaN(interestRate) || interestRate <= 0 ||
isNaN(loanTerm) || loanTerm <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
// Debt-to-Income Ratio (DTI) guideline: Lenders typically prefer a DTI of 43% or less.
// This includes PITI (Principal, Interest, Taxes, Insurance) plus other debts.
// For simplicity, we'll estimate the maximum PITI based on income and existing debts.
var maxDTI = 0.43;
var maxMonthlyPayment = (grossMonthlyIncome * maxDTI) – currentMonthlyDebts;
if (maxMonthlyPayment 0) {
maxLoanAmount = maxMonthlyPayment * (1 – Math.pow(1 + monthlyInterestRate, -numberOfMonths)) / monthlyInterestRate;
} else { // Handle 0% interest rate case
maxLoanAmount = maxMonthlyPayment * numberOfMonths;
}
var affordableMortgage = maxLoanAmount – downPayment;
if (affordableMortgage < 0) {
affordableMortgage = 0; // Cannot have a negative affordable mortgage
}
resultDiv.innerHTML = "Estimated Maximum Affordable Mortgage:
$" + affordableMortgage.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",") + "";
}