-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperty-tax-calculator.js
More file actions
55 lines (47 loc) · 1.91 KB
/
Copy pathproperty-tax-calculator.js
File metadata and controls
55 lines (47 loc) · 1.91 KB
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
window.onload = function () {
const millageRatesJsonUrl = '/wp-content/scripts/millage-rates-2023.json';
const ownerOccupantRate = 0.04; // 4%
const allOtherRate = 0.06; // 6%
const homeValueInput = document.getElementById('homeValue');
const taxDistrictSelect = document.getElementById('taxDistrict');
const estimateButton = document.getElementById('calculateTax');
const estimatedTaxParagraph = document.getElementById('estimatedTax');
function calculateTax() {
const homeValue = parseFloat(homeValueInput.value);
const taxDistrictId = parseInt(taxDistrictSelect.value);
const isOwnerOccupant = document.getElementById('ownerOccupant').checked;
fetch(millageRatesJsonUrl)
.then(response => response.json())
.then(data => {
const selectedTaxDistrict = data.taxDistricts.find(district => district.id === taxDistrictId);
const millageRate = selectedTaxDistrict.millageRate;
let taxRate;
if (isOwnerOccupant) {
taxRate = ownerOccupantRate + selectedTaxDistrict.cityTaxRelief;
} else {
taxRate = allOtherRate;
}
const estimatedTax = homeValue * taxRate * millageRate;
estimatedTaxParagraph.textContent = `Estimated Property Tax: $${estimatedTax.toFixed(2)}`;
})
.catch(error => {
console.error(error);
estimatedTaxParagraph.textContent = 'Error: Unable to calculate estimated tax.';
});
}
estimateButton.addEventListener('click', calculateTax);
// Populate the tax district dropdown menu
fetch(millageRatesJsonUrl)
.then(response => response.json())
.then(data => {
data.taxDistricts.forEach(district => {
const option = document.createElement('option');
option.value = district.id;
option.textContent = district.name;
taxDistrictSelect.appendChild(option);
});
})
.catch(error => {
console.error(error);
});
};