i was wondering if yous could help me with this. I am quite new to JavaScript but This has been getting to me for quite a while now and I have ran out of ideas on how to fix this. Basically If a user clicks on one of those checkboxes below, then the Data-price attribute of the checkboxes should show in the total box and so fourth. e.g user clicks the checkbox with the value of 14, then the price £13 will show up in the total box, if the user clicks on another checkbox, say the last checkbox with the value of 9, then it will calculate the two checkboxes 16 + 13 and will then show up the new figure in the total box
I have tried my code countless of times and it will not display anything in the total box. I really hope i have made myself clear with this and i'd be grateful if yous can help me out
HTML
<form id=BookingForm method="get"
<section id="bookEvents"
<div class="item">
<input type='checkbox' name='event[]' value='6' data-price='18.50'>
<input type='checkbox' name='event[]' value='14' data-price='13.00'>
<input type='checkbox' name='event[]' value='11' data-price='35.00'>
<input type='checkbox' name='event[]' value='9' data-price='16.00'>
</div>
</section>
<section id="checkCost">
Total <input type="text" name="total" size="10" readonly>
</section>
JavaScript
window.addEventListener('load', function () {
"use strict";
const l_form = document.getElementById('bookingForm');
l_form.CheckValue.onclick = calculateTotal;
function calculateTotal() {
let l_total = 0;
const l_item = l_form.querySelectorAll('div.item');
const l_checkboxesCount = l_checkboxes.length;
for (let t_i = 0; t_i < l_checkboxesCount; t_i++) {
const t_item = l_item[t_i];
const t_checkbox = t_ckbox.querySelector('input[data-value][type=checkbox]');
if (t_checkbox.checked) {
l_total += t_checkbox.dataset.price;
}
l_form.submit.value = l_total;
}
}
});
id=BookingFormshould beid="BookingForm". And later when you use it indocument.getElementById('bookingForm'), it should bedocument.getElementById('BookingForm')to match the case. Start with that and keep debugging. Look at your console, it's crystal clear what the issues are.});to the code... it's possible they forgot to include it when they wrote the question, but we simply don't know that