Tax Deduction | Sport Expenses Tax Deduction | Sport Expenses Number of children Invalid. Please check your data and try again. Results Total Expenses: Total tax deduction: Details: School fees ` } data.innerHTML = res } function readChildrenInput() { let res = "" for (let i = 1; i<= children; i++) { let fees = document.getElementById(`school-fees-${i}`) let age = document.getElementById(`age-${i}`) res += `f${i}=${fees.value}&a${i}=${age.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 = `sport_exp?num=${number.value}&${res}` 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'; }