Tax Deduction | University Expenses

Tax Deduction | University Expenses

Invalid. Please check your data and try again.

Results

Total Expenses:

Total tax deduction:

Details:

` } data.innerHTML = res } function readChildrenInput() { let res = "" for (let i = 1; i<= children; i++) { let fees = document.getElementById(`school-fees-${i}`) let type = document.getElementById(`type-${i}`) let location = document.getElementById(`location-${i}`) res += `f${i}=${fees.value}&t${i}=${type.value}&l${i}=${location.value}&` } return res } let children = 0 const number = document.getElementById('number-ppl'); number.oninput = (e) => { children = e.target.value; generateChildrenInput(children) } const errormsg = document.querySelector('.error-msg'); const resy = document.getElementById('res'); const interests = document.getElementById('interests'); const button = document.getElementById('calculate'); const total = document.getElementById('total'); const deduction = document.getElementById('deduction'); const details = document.getElementById('details'); button.addEventListener('click', calculate); function call(path, callback) { const BASE_URL = 'https://us-central1-income-tax-calculator-nicola.cloudfunctions.net/'; var request = new XMLHttpRequest(); var url = `${BASE_URL}/${path}`; request.open("GET", url, true); request.onreadystatechange = function () { if (request.readyState === 4) { callback(JSON.parse(request.response)); } }; request.onerror = function(e) { error({err: "Something went wrong. Please try again later"}) } request.send(); } function calculate(e) { e.preventDefault(); errormsg.style.display = 'none'; results.style.display = 'none'; const res = readChildrenInput() const path = `univ_exp?num=${number.value}&${res}` console.log(path); call(path, r => { if (!r.res) { return error(r) } success(r.res) }); } function error(data) { errormsg.style.display = 'block'; errormsg.innerText = data.err; } function getEuro(value) { let options = { style: 'currency', currency: 'EUR' }; return new Intl.NumberFormat('en-US', options).format(value); } function success(data) { total.innerText = getEuro(data.t); deduction.innerText = getEuro(data.d); let details_text = "" for (let i = 1; i <= parseFloat(data.n); i++) { details_text += `Child ${i} Total Expenses: ${getEuro(data.r[i].t)} Tax Deduction: ${getEuro(data.r[i].d)} ` } details.innerText = details_text; results.style.display = 'block'; }
Scroll to Top