Mortgage Affordability Calculator
Use this calculator to estimate how much house you can afford based on your income, debts, and desired mortgage terms.
.calculator-container {
font-family: sans-serif;
border: 1px solid #ddd;
padding: 20px;
border-radius: 8px;
max-width: 600px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
margin-bottom: 15px;
color: #333;
}
.calculator-container p {
text-align: center;
margin-bottom: 25px;
color: #555;
}
.calculator-inputs {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-bottom: 20px;
}
.input-group {
display: flex;
flex-direction: column;
}
.input-group label {
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.input-group input {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1em;
}
button {
display: block;
width: 100%;
padding: 12px 15px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
font-size: 1.1em;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
border: 1px solid #e0e0e0;
border-radius: 5px;
background-color: #eef;
text-align: center;
font-size: 1.1em;
color: #333;
}
.calculator-result strong {
color: #007bff;
}
function calculateMortgageAffordability() {
var annualIncome = parseFloat(document.getElementById("annualIncome").value);
var existingDebt = parseFloat(document.getElementById("existingDebt").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var interestRate = parseFloat(document.getElementById("interestRate").value);
var loanTerm = parseFloat(document.getElementById("loanTerm").value);
var propertyTaxes = parseFloat(document.getElementById("propertyTaxes").value);
var homeInsurance = parseFloat(document.getElementById("homeInsurance").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(annualIncome) || isNaN(existingDebt) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTerm) || isNaN(propertyTaxes) || isNaN(homeInsurance)) {
resultDiv.innerHTML = "Please enter valid numbers for all fields.";
return;
}
// Lenders typically use the 28/36 rule (front-end and back-end ratios)
// Front-end ratio (Housing costs / Gross Income) should be <= 28%
// Back-end ratio (Total Debt / Gross Income) should be <= 36%
var grossMonthlyIncome = annualIncome / 12;
var maxHousingPayment = grossMonthlyIncome * 0.28; // PITI (Principal, Interest, Taxes, Insurance)
var maxTotalDebtPayment = grossMonthlyIncome * 0.36;
// Maximum allowable monthly debt payment including proposed mortgage
var maxAllowedMortgagePayment = maxTotalDebtPayment – existingDebt;
// We'll use the more restrictive of the two limits (front-end vs back-end)
var maxMonthlyPITI = Math.min(maxHousingPayment, maxAllowedMortgagePayment);
if (maxMonthlyPITI <= 0) {
resultDiv.innerHTML = "Based on your income and existing debt, you may not qualify for a mortgage at this time.";
return;
}
// Calculate P&I (Principal & Interest) portion of the payment
var monthlyPropertyTaxes = propertyTaxes / 12;
var monthlyHomeInsurance = homeInsurance / 12;
var maxMonthlyPI = maxMonthlyPITI – monthlyPropertyTaxes – monthlyHomeInsurance;
if (maxMonthlyPI 0 && numberOfPayments > 0) {
maxLoanAmount = maxMonthlyPI * (Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1) / (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments));
} else if (maxMonthlyPI > 0) { // Case for 0% interest or 0 term (though unlikely for mortgages)
maxLoanAmount = maxMonthlyPI * numberOfPayments; // Simple linear calculation
}
var estimatedHomeAffordability = maxLoanAmount + downPayment;
resultDiv.innerHTML = "Estimated Maximum Home Affordability:
$" + estimatedHomeAffordability.toFixed(2) + "" +
"(Based on a maximum monthly PITI payment of $" + maxMonthlyPITI.toFixed(2) + ")";
}