-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
711 lines (660 loc) · 24.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Head Start Housing Adjustment Calculator</title>
<link
href="https://fonts.googleapis.com/css2?family=Lato&family=Roboto:wght@400;700&display=swap"
rel="stylesheet"
/>
<style>
/*
CSS Variables for consistent color scheme.
Using variables allows easy updates to the color palette and ensures consistency.
*/
:root {
--text-color: #333333;
--link-color: #007b8d;
--heading-color: #264b65;
--button-color: #0063a6;
--button-hover-color: #004d80;
--error-color: #e51937;
--background-color: #f9f9f9;
--step-background: #ffffff;
}
/* Global styles applied to the entire body of the document */
body {
font-family: "Lato", sans-serif; /* Primary font for body text */
font-size: 16px; /* Base font size */
line-height: 1.6; /* Improves readability */
color: var(--text-color); /* Sets text color using CSS variable */
max-width: 800px; /* Limits the width for better readability */
margin: 0 auto; /* Centers the content horizontally */
padding: 20px; /* Adds spacing around the content */
background-color: var(--background-color); /* Sets background color */
}
/* Typography styles for headings */
h1,
h2,
h3 {
font-family: "Roboto", sans-serif; /* Different font for headings */
color: var(--heading-color); /* Sets heading color */
}
/* Specific font sizes for different heading levels */
h1 {
font-size: 2em;
}
h2 {
font-size: 1.5em;
}
h3 {
font-size: 1.25em;
}
/* Styles for the calculator form container */
.calculator {
background-color: var(--step-background); /* Background color */
border-radius: 8px; /* Rounded corners */
padding: 20px; /* Inner spacing */
margin-bottom: 20px; /* Spacing below the form */
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Subtle shadow for depth */
}
/* Styles for each step section within the form */
.step {
margin-bottom: 20px; /* Spacing below each step */
padding: 15px; /* Inner spacing */
background-color: var(--background-color); /* Background color */
border-radius: 4px; /* Rounded corners */
}
/* Styles for fieldsets, which group related form elements */
fieldset {
border: 1px solid #ccc; /* Border color */
border-radius: 4px; /* Rounded corners */
padding: 10px; /* Inner spacing */
margin-bottom: 15px; /* Spacing below the fieldset */
}
/* Styles for legends, which provide captions for fieldsets */
legend {
font-weight: bold; /* Bold text */
padding: 0 5px; /* Horizontal padding */
}
/* Styles for labels associated with form inputs */
label {
display: block; /* Ensures labels take up full width */
margin-top: 10px; /* Spacing above labels */
font-weight: bold; /* Bold text */
}
/* Container for input groups, arranging inputs side by side */
.input-group {
display: flex; /* Flexbox for layout */
justify-content: space-between; /* Even spacing between items */
gap: 10px; /* Space between flex items */
margin-bottom: 15px; /* Spacing below input groups */
}
/* Styles for number inputs within input groups */
.input-group input[type="number"] {
flex: 1; /* Allows inputs to grow and fill space */
padding: 8px; /* Inner spacing */
font-size: 16px; /* Font size */
border: 1px solid #ccc; /* Border color */
border-radius: 4px; /* Rounded corners */
}
/* Styles for buttons */
button {
background-color: var(--button-color); /* Button background color */
color: white; /* Text color */
border: none; /* Removes default border */
padding: 12px 24px; /* Inner spacing */
margin-top: 20px; /* Spacing above button */
cursor: pointer; /* Pointer cursor on hover */
border-radius: 4px; /* Rounded corners */
font-size: 18px; /* Font size */
transition: background-color 0.3s; /* Smooth transition for hover effect */
}
/* Hover and focus states for buttons */
button:hover,
button:focus {
background-color: var(
--button-hover-color
); /* Darker background on hover/focus */
}
/* Styles for error messages */
.error-message {
color: var(--error-color); /* Error text color */
font-size: 0.9em; /* Slightly smaller font size */
margin-top: 5px; /* Spacing above error message */
}
/* Styles for the result display area */
.result {
margin-top: 20px; /* Spacing above results */
padding: 15px; /* Inner spacing */
background-color: var(--step-background); /* Background color */
border-radius: 4px; /* Rounded corners */
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* Subtle shadow */
}
/* Styles for caveat text */
.caveat {
font-style: italic; /* Italic text */
color: #666666; /* Gray text color */
margin-top: 20px; /* Spacing above caveat */
}
/* Styles for the explanation box */
.explanation {
background-color: #e6f3ff; /* Light blue background */
border: 1px solid #b3d9ff; /* Border color */
border-radius: 4px; /* Rounded corners */
padding: 15px; /* Inner spacing */
margin-bottom: 20px; /* Spacing below explanation */
/* Removed italic style for accessibility compliance */
}
/* Styles for tooltips */
.tooltip {
position: relative; /* Positioning context for tooltip text */
display: inline-block; /* Allows tooltip to be inline with text */
cursor: help; /* Indicates additional information is available */
}
/* Styles for the tooltip text */
.tooltip .tooltiptext {
visibility: hidden; /* Hidden by default */
width: 300px; /* Fixed width */
background-color: #555; /* Dark background */
color: #fff; /* White text */
text-align: center; /* Centered text */
border-radius: 6px; /* Rounded corners */
padding: 10px; /* Inner spacing */
position: absolute; /* Absolute positioning */
z-index: 1; /* Ensures tooltip appears above other elements */
bottom: 125%; /* Positions tooltip above the icon */
left: 50%; /* Centers tooltip horizontally */
margin-left: -150px; /* Centers tooltip based on width */
opacity: 0; /* Transparent by default */
transition: opacity 0.3s; /* Smooth fade-in effect */
}
/* Show tooltip text on hover */
.tooltip:hover .tooltiptext {
visibility: visible; /* Makes tooltip visible */
opacity: 1; /* Fully opaque */
}
/* Responsive design for smaller screens */
@media screen and (max-width: 768px) {
.input-group {
flex-direction: column; /* Stacks inputs vertically */
}
button {
width: 100%; /* Button takes full width */
}
}
</style>
</head>
<body>
<header>
<!--
Main heading of the page.
The id "main-heading" can be used for accessibility and scripting purposes.
-->
<h1 id="main-heading">Head Start Housing Adjustment Calculator</h1>
</header>
<main>
<!--
Explanation box providing context and instructions for the calculator.
Helps users understand the purpose and how to use the tool.
-->
<div class="explanation">
Use this tool to adjust family gross income for excessive housing costs
when making income eligibility determinations. Housing costs are
considered excessive when they exceed 30% of the total gross household
income. To use this tool, complete the fields below. The adjusted gross
household income will be displayed at the end based on the values
provided.
</div>
<!--
Form for the housing calculator.
The form uses semantic HTML elements and ARIA attributes for accessibility.
-->
<form
id="housing-calculator"
class="calculator"
aria-labelledby="calc-heading"
>
<h2 id="calc-heading">Enter Your Information</h2>
<!-- Step 1: Income Section -->
<section id="step1" class="step">
<h3>
Step 1: Income
<!-- Tooltip providing additional information about income calculation -->
<span class="tooltip"
>ℹ️
<span class="tooltiptext"
>Calculate and enter total household gross income for the family
and input it into the following field. Note the definition for
"income" has been revised in Section 1305.2.</span
>
</span>
</h3>
<fieldset>
<legend>Household Income</legend>
<!-- Label for the income input field -->
<label for="income">Total Household Income</label>
<div class="input-group">
<!--
Input for total household income.
Attributes ensure proper input types, accessibility, and validation.
-->
<input
type="number"
id="income"
name="income"
placeholder="Enter household income"
required
aria-required="true"
min="0"
step="0.01"
/>
</div>
<!-- Container for displaying error messages related to income input -->
<div
id="income-error"
class="error-message"
aria-live="polite"
></div>
</fieldset>
</section>
<!-- Step 2: Housing Costs Section -->
<section id="step2" class="step">
<h3>
Step 2: Housing Costs
<!-- Tooltip providing additional information about entering housing costs -->
<span class="tooltip"
>ℹ️
<span class="tooltiptext"
>Enter the payment amount and number of payments for housing
costs listed using available bills, bank statements, and other
relevant documentation provided by the family.</span
>
</span>
</h3>
<fieldset>
<legend>Monthly Housing Expenses</legend>
<!-- Rent input fields -->
<label for="rent">Rent</label>
<div class="input-group">
<input
type="number"
id="rent"
name="rent"
placeholder="Payment amount"
min="0"
step="0.01"
aria-label="Rent payment amount"
/>
<input
type="number"
id="rentPayments"
name="rentPayments"
placeholder="Payments per year"
min="0"
max="12"
step="1"
aria-label="Number of rent payments per year"
/>
</div>
<!-- Renters Insurance input fields -->
<label for="rentersInsurance">Renters Insurance</label>
<div class="input-group">
<input
type="number"
id="rentersInsurance"
name="rentersInsurance"
placeholder="Payment amount"
min="0"
step="0.01"
aria-label="Renters insurance payment amount"
/>
<input
type="number"
id="rentersInsurancePayments"
name="rentersInsurancePayments"
placeholder="Payments per year"
min="0"
max="12"
step="1"
aria-label="Number of renters insurance payments per year"
/>
</div>
<!-- Mortgage Payment input fields -->
<label for="mortgage">Mortgage Payment</label>
<div class="input-group">
<input
type="number"
id="mortgage"
name="mortgage"
placeholder="Payment amount"
min="0"
step="0.01"
aria-label="Mortgage payment amount"
/>
<input
type="number"
id="mortgagePayments"
name="mortgagePayments"
placeholder="Payments per year"
min="0"
max="12"
step="1"
aria-label="Number of mortgage payments per year"
/>
</div>
<!-- Homeowners Insurance input fields -->
<label for="homeownersInsurance">Homeowners Insurance</label>
<div class="input-group">
<input
type="number"
id="homeownersInsurance"
name="homeownersInsurance"
placeholder="Payment amount"
min="0"
step="0.01"
aria-label="Homeowners insurance payment amount"
/>
<input
type="number"
id="homeownersInsurancePayments"
name="homeownersInsurancePayments"
placeholder="Payments per year"
min="0"
max="12"
step="1"
aria-label="Number of homeowners insurance payments per year"
/>
</div>
<!-- Mortgage Interest input fields -->
<label for="mortgageInterest">Mortgage Interest</label>
<div class="input-group">
<input
type="number"
id="mortgageInterest"
name="mortgageInterest"
placeholder="Payment amount"
min="0"
step="0.01"
aria-label="Mortgage interest payment amount"
/>
<input
type="number"
id="mortgageInterestPayments"
name="mortgageInterestPayments"
placeholder="Payments per year"
min="0"
max="12"
step="1"
aria-label="Number of mortgage interest payments per year"
/>
</div>
<!-- Property or Renter Taxes input fields -->
<label for="propertyTaxes">Property or Renter Taxes</label>
<div class="input-group">
<input
type="number"
id="propertyTaxes"
name="propertyTaxes"
placeholder="Payment amount"
min="0"
step="0.01"
aria-label="Property or renter taxes payment amount"
/>
<input
type="number"
id="propertyTaxesPayments"
name="propertyTaxesPayments"
placeholder="Payments per year"
min="0"
max="12"
step="1"
aria-label="Number of property or renter taxes payments per year"
/>
</div>
<!-- Electricity input fields -->
<label for="electricity">Electricity</label>
<div class="input-group">
<input
type="number"
id="electricity"
name="electricity"
placeholder="Payment amount"
min="0"
step="0.01"
aria-label="Electricity payment amount"
/>
<input
type="number"
id="electricityPayments"
name="electricityPayments"
placeholder="Payments per year"
min="0"
max="12"
step="1"
aria-label="Number of electricity payments per year"
/>
</div>
<!-- Gas input fields -->
<label for="gas">Gas</label>
<div class="input-group">
<input
type="number"
id="gas"
name="gas"
placeholder="Payment amount"
min="0"
step="0.01"
aria-label="Gas payment amount"
/>
<input
type="number"
id="gasPayments"
name="gasPayments"
placeholder="Payments per year"
min="0"
max="12"
step="1"
aria-label="Number of gas payments per year"
/>
</div>
<!-- Water input fields -->
<label for="water">Water</label>
<div class="input-group">
<input
type="number"
id="water"
name="water"
placeholder="Payment amount"
min="0"
step="0.01"
aria-label="Water payment amount"
/>
<input
type="number"
id="waterPayments"
name="waterPayments"
placeholder="Payments per year"
min="0"
max="12"
step="1"
aria-label="Number of water payments per year"
/>
</div>
<!-- Sewer input fields -->
<label for="sewer">Sewer</label>
<div class="input-group">
<input
type="number"
id="sewer"
name="sewer"
placeholder="Payment amount"
min="0"
step="0.01"
aria-label="Sewer payment amount"
/>
<input
type="number"
id="sewerPayments"
name="sewerPayments"
placeholder="Payments per year"
min="0"
max="12"
step="1"
aria-label="Number of sewer payments per year"
/>
</div>
<!-- Trash input fields -->
<label for="trash">Trash</label>
<div class="input-group">
<input
type="number"
id="trash"
name="trash"
placeholder="Payment amount"
min="0"
step="0.01"
aria-label="Trash payment amount"
/>
<input
type="number"
id="trashPayments"
name="trashPayments"
placeholder="Payments per year"
min="0"
max="12"
step="1"
aria-label="Number of trash payments per year"
/>
</div>
</fieldset>
</section>
<!--
Submit button to trigger the calculation.
Accessible by keyboard and screen readers.
-->
<button type="submit" id="calculate-button">
Calculate Adjustment
</button>
</form>
<!--
Result display area.
Initially hidden and revealed after calculation.
Uses ARIA roles for accessibility.
-->
<div
id="result"
class="result"
style="display: none"
role="region"
aria-live="polite"
></div>
<!--
Caveat note providing additional information and disclaimers.
-->
<p class="caveat">
Note: This calculator provides an estimate for housing adjustment.
Please speak with a Head Start representative for official
determinations and provide supporting documents.
</p>
</main>
<script>
// Main calculation function triggered on form submission
function calculateAdjustment(event) {
event.preventDefault(); // Prevents the default form submission behavior
try {
// Get the total household income from the input field
const income = getNumberInput("income");
// Define the housing cost categories as an array of input IDs
const housingCategories = [
"rent",
"rentersInsurance",
"mortgage",
"homeownersInsurance",
"mortgageInterest",
"propertyTaxes",
"electricity",
"gas",
"water",
"sewer",
"trash",
];
// Calculate total housing costs by summing each category's annual cost
const totalHousingCosts = housingCategories.reduce(
(total, category) => {
const amount = getNumberInput(category) || 0; // Payment amount
const payments = getNumberInput(category + "Payments") || 0; // Number of payments per year
return total + amount * payments; // Adds the annual cost to the total
},
0 // Initial value for the total
);
// Calculate 30% of the total household income
const thirtyPercentIncome = income * 0.3;
// Calculate excess housing costs if total exceeds 30% of income
const excessHousingCosts = Math.max(
0,
totalHousingCosts - thirtyPercentIncome
);
// Calculate the adjusted income by subtracting excess housing costs
const adjustedIncome = income - excessHousingCosts;
// Display the results to the user
displayResults(
totalHousingCosts,
thirtyPercentIncome,
excessHousingCosts,
adjustedIncome
);
} catch (error) {
// Log the error for debugging purposes
console.error("Calculation error:", error);
// Display a user-friendly error message
displayError(
"An error occurred during calculation. Please check your inputs and try again."
);
}
}
// Helper function to retrieve and parse numeric input values
function getNumberInput(id) {
const value = parseFloat(document.getElementById(id).value);
return isNaN(value) ? 0 : value; // Returns 0 if input is not a number
}
// Function to display calculation results in the result area
function displayResults(
totalHousingCosts,
thirtyPercentIncome,
excessHousingCosts,
adjustedIncome
) {
// Template literal to format the results HTML
const resultHtml = `
<h2>Results</h2>
<p>Total Annual Housing Costs: $${totalHousingCosts.toFixed(2)}</p>
<p>30% of Total Household Income: $${thirtyPercentIncome.toFixed(
2
)}</p>
<p>Do housing costs exceed 30% of total household income? <strong>${
totalHousingCosts > thirtyPercentIncome ? "Yes" : "No"
}</strong></p>
<p>Total Housing Deduction: $${excessHousingCosts.toFixed(2)}</p>
<p>Adjusted Household Income: $${adjustedIncome.toFixed(2)}</p>
`;
// Select the result element and update its content
const resultElement = document.getElementById("result");
resultElement.innerHTML = resultHtml; // Inserts the results HTML
resultElement.style.display = "block"; // Makes the result area visible
}
// Function to display error messages to the user
function displayError(message) {
const errorElement = document.createElement("div"); // Creates a new div element
errorElement.className = "error-message"; // Assigns the error message class
errorElement.textContent = message; // Sets the error message text
document.getElementById("result").appendChild(errorElement); // Appends the error to the result area
}
// Event listener for form submission to trigger calculation
document
.getElementById("housing-calculator")
.addEventListener("submit", calculateAdjustment);
</script>
</body>
</html>