Mortgage Affordability Calculator
Use this calculator to estimate how much you can afford to borrow for a mortgage. It considers your income, debts, and desired monthly payment.
.calculator-container {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-inputs {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
margin-bottom: 20px;
}
.input-group {
display: flex;
flex-direction: column;
}
.input-group label {
margin-bottom: 5px;
font-weight: bold;
font-size: 0.9em;
}
.input-group input {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box; /* Ensure padding doesn't affect width */
}
button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1.1em;
margin-top: 10px;
}
button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 20px;
padding: 15px;
border: 1px solid #d4edda;
background-color: #d4edda;
color: #155724;
border-radius: 4px;
text-align: center;
font-size: 1.1em;
font-weight: bold;
}
function calculateMortgageAffordability() {
var grossIncome = parseFloat(document.getElementById("grossIncome").value);
var monthlyDebt = parseFloat(document.getElementById("monthlyDebt").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 pmi = parseFloat(document.getElementById("pmi").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
// Input validation
if (isNaN(grossIncome) || grossIncome <= 0 ||
isNaN(monthlyDebt) || monthlyDebt < 0 ||
isNaN(downPayment) || downPayment < 0 ||
isNaN(interestRate) || interestRate <= 0 ||
isNaN(loanTerm) || loanTerm <= 0 ||
isNaN(propertyTaxes) || propertyTaxes < 0 ||
isNaN(homeInsurance) || homeInsurance < 0 ||
isNaN(pmi) || pmi < 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
// Lender Debt-to-Income (DTI) Ratios (common guidelines)
// Front-end DTI (housing costs) typically 28%
// Back-end DTI (all debts) typically 36%
// These are general guidelines and can vary by lender and loan type.
var maxFrontEndDTI = 0.28;
var maxBackEndDTI = 0.36;
var monthlyGrossIncome = grossIncome / 12;
// Calculate maximum affordable monthly housing payment (Principal, Interest, Taxes, Insurance – PITI)
var maxHousingPayment = monthlyGrossIncome * maxFrontEndDTI;
// Calculate maximum total monthly debt payment allowed
var maxTotalDebtPayment = monthlyGrossIncome * maxBackEndDTI;
// The actual maximum monthly PITI is constrained by the back-end DTI,
// considering existing debts.
var availableForMortgagePayment = maxTotalDebtPayment – monthlyDebt;
// The more conservative of the two limits (front-end or back-end constraint)
var affordableMonthlyPITI = Math.min(maxHousingPayment, availableForMortgagePayment);
if (affordableMonthlyPITI <= 0) {
resultDiv.innerHTML = "Based on your income and debts, you may not qualify for a mortgage at this time.";
return;
}
// Separate PITI components
var monthlyPropertyTaxes = propertyTaxes / 12;
var monthlyHomeInsurance = homeInsurance / 12;
var monthlyPMI = pmi / 12;
// Calculate the portion of the affordable PITI that can go towards Principal & Interest (PI)
var affordableMonthlyPI = affordableMonthlyPITI – monthlyPropertyTaxes – monthlyHomeInsurance – monthlyPMI;
if (affordableMonthlyPI 0) { // Avoid division by zero if interest rate is 0
maxLoanAmount = affordableMonthlyPI * (1 – Math.pow(1 + r, -n)) / r;
} else { // If interest rate is 0, loan amount is simply monthly PI * number of payments
maxLoanAmount = affordableMonthlyPI * n;
}
var maxHomePrice = maxLoanAmount + downPayment;
resultDiv.innerHTML = "
Estimated Affordability
" +
"Maximum Affordable Monthly PITI:
$" + affordableMonthlyPITI.toFixed(2) + "" +
"Maximum Loan Amount:
$" + maxLoanAmount.toFixed(2) + "" +
"Estimated Maximum Home Price (with down payment):
$" + maxHomePrice.toFixed(2) + "";
}