#home-affordability-tool {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
max-width: 800px;
margin: 20px auto;
padding: 30px;
border: 1px solid #e1e1e1;
border-radius: 12px;
background-color: #ffffff;
box-shadow: 0 4px 15px rgba(0,0,0,0.05);
color: #333;
}
#home-affordability-tool h2 {
color: #1a365d;
margin-top: 0;
border-bottom: 2px solid #f0f0f0;
padding-bottom: 10px;
}
.calc-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 25px;
}
.input-group {
display: flex;
flex-direction: column;
}
.input-group label {
font-weight: 600;
margin-bottom: 8px;
font-size: 14px;
color: #4a5568;
}
.input-group input {
padding: 12px;
border: 1px solid #cbd5e0;
border-radius: 6px;
font-size: 16px;
transition: border-color 0.2s;
}
.input-group input:focus {
border-color: #3182ce;
outline: none;
}
#calc-btn {
grid-column: span 2;
background-color: #2b6cb0;
color: white;
padding: 15px;
border: none;
border-radius: 6px;
font-size: 18px;
font-weight: bold;
cursor: pointer;
transition: background-color 0.2s;
}
#calc-btn:hover {
background-color: #2c5282;
}
#affordability-result {
margin-top: 30px;
padding: 25px;
background-color: #f7fafc;
border-radius: 8px;
text-align: center;
display: none;
}
.result-value {
font-size: 32px;
font-weight: 800;
color: #2f855a;
margin: 10px 0;
}
.result-breakdown {
font-size: 14px;
color: #718096;
line-height: 1.6;
}
.article-section {
margin-top: 40px;
line-height: 1.7;
color: #2d3748;
}
.article-section h3 {
color: #2d3748;
margin-top: 30px;
}
@media (max-width: 600px) {
.calc-grid { grid-template-columns: 1fr; }
#calc-btn { grid-column: span 1; }
}
function calculateAffordability() {
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 / 12;
var loanTermMonths = parseFloat(document.getElementById('loanTerm').value) * 12;
var taxRate = parseFloat(document.getElementById('propertyTax').value) / 100 / 12;
if (isNaN(annualIncome) || isNaN(interestRate) || isNaN(downPayment)) {
alert("Please enter valid numerical values.");
return;
}
// 1. Determine Monthly Income
var monthlyGross = annualIncome / 12;
// 2. Use 36% DTI rule to find max total monthly payment
var maxTotalMonthlyPayment = monthlyGross * 0.36;
// 3. Subtract existing debts
var availableForPITI = maxTotalMonthlyPayment – monthlyDebt;
// 4. Estimate Home Insurance and extra costs (0.5% of home value annually as buffer)
// We assume PITI: Principal + Interest + Tax + Insurance
// Monthly P&I = P * [ i(1 + i)^n ] / [ (1 + i)^n – 1 ]
// var Price = Loan + DownPayment
// Monthly Tax = Price * taxRate
// Monthly Ins = Price * (0.005 / 12)
// Formula derivation to solve for Home Price (H):
// PITI = [(H – Down) * factor] + (H * taxRate) + (H * insuranceRate)
// PITI = H * factor – Down * factor + H * taxRate + H * insuranceRate
// PITI + Down * factor = H * (factor + taxRate + insuranceRate)
// H = (PITI + Down * factor) / (factor + taxRate + insuranceRate)
var i = interestRate;
var n = loanTermMonths;
var factor = (i * Math.pow(1 + i, n)) / (Math.pow(1 + i, n) – 1);
var insuranceRate = 0.005 / 12; // Standard 0.5% annual estimate
var maxHomePrice = (availableForPITI + (downPayment * factor)) / (factor + taxRate + insuranceRate);
if (maxHomePrice < downPayment) {
maxHomePrice = downPayment;
}
var monthlyPI = (maxHomePrice – downPayment) * factor;
var monthlyTaxes = maxHomePrice * taxRate;
var monthlyIns = maxHomePrice * insuranceRate;
// Display Results
document.getElementById('affordability-result').style.display = 'block';
document.getElementById('maxHomePrice').innerHTML = '$' + Math.round(maxHomePrice).toLocaleString();
document.getElementById('resultDetails').innerHTML =
'
Monthly Payment Breakdown:' +
'Principal & Interest: $' + Math.round(monthlyPI).toLocaleString() + " +
'Estimated Taxes: $' + Math.round(monthlyTaxes).toLocaleString() + " +
'Estimated Insurance: $' + Math.round(monthlyIns).toLocaleString() + " +
'
Total Monthly PITI: $' + Math.round(monthlyPI + monthlyTaxes + monthlyIns).toLocaleString() + '';
}