Hi there,
I am trying to figure out how to create five checkboxes each with a specific value assigned to them. When a visiter clicks the checkboxes whichever has been clicked is added up and gives a total in a box below.
So basically I just need help figuring out how to assign a value to each checkbox and then how to connect them tp tally up everything.
Can anyone help me do this?
Thanks!
Hi
This does the trick (did for 3, complete to as much as needed).
$w.onReady(function () {
$w("#checkbox1").value = "1";
$w("#checkbox2").value = "2";
$w("#checkbox5").value = "3";
$w("#checkbox1").onChange( (event, $w) => {
manageSum();
} );
$w("#checkbox2").onChange( (event, $w) => {
manageSum();
} );
$w("#checkbox5").onChange( (event, $w) => {
manageSum();
} );
manageSum();
});
function manageSum(){
var sum = 0;
if ($w("#checkbox1").checked) sum += Number($w("#checkbox1").value);
if ($w("#checkbox2").checked) sum += Number($w("#checkbox2").value);
if ($w("#checkbox5").checked) sum += Number($w("#checkbox5").value);
$w("#text18").text = ""+sum;
}
Thank you so much for supplying that! I haven’t worked much with the code section of Wix, so are you able to point me in the direction of where I would put that code?
My pleasure.
For front code, you put it in the code panel of your page. You’ll find relevant info here: Velo: Working in the Code Panel | Help Center | Wix.com.
Let me know if you need more help.
Thank you so much! I was able to figure it out with your help!