I know I need to code this, and I’ve been trying to figure out how, but struggling.
I’ve got a page with a series of checkboxes and every time a client checks one I’d like to add a set amount to a total. When they uncheck it I’d like the total to no longer include that amount. The total needs to be displayed on the same page as the checkboxes. Anyone have any idea if this even possible and if so what I need to code to make it happen?
The easiest way is to create a function to check the status of each checkbox and add its value to the total.
Then simply call the calculateTotal() function on the onChange event of each checkbox.
function calculateTotal() {
let total = 0;
if ($w('#checkbox1').checked) {total += Number($w('#checkbox1').value)}
if ($w('#checkbox2').checked) {total += Number($w('#checkbox2').value)}
if ($w('#checkbox3').checked) {total += Number($w('#checkbox3').value)}
if ($w('#checkbox4').checked) {total += Number($w('#checkbox4').value)}
$w('#total').text = String(total);
}