I am trying to compare two sets of checkboxes to equal a total number of selected items. As there are 19 options but I only want them to be able to select 6 choices for a button to show up.
I have this code and it works great for one multi-checkbox but not for both as I have not even added the second multi-checkbox as am not sure how to compare them so they add to a total of 6 selected.
@russian-dima Thanks again! I applied the code and checked the console on both Chrome and Wix and the arrays remain at 0 no matter how many I select. So that explains why it will never activate the button as it is not adding to 6.
I applied the code and checked the console on both Chrome and Wix and the arrays remain at 0 no matter how many I select. So that explains why it will never activate the button as it is not adding to 6.
Exactly!!!
Well done…Sherlock Holmes
@russian-dima I just wanted to let you know I figured it out thanks to you. It took a bunch of trial and error but now my code is comparing both multi-checkboxes to activate the button only if the total is equal to 6.
Here is the code.
$w.onReady(function () {
$w("#checkboxGroup1").onChange(CartButtonEnableDisable);
$w("#checkboxGroup2").onChange(CartButtonEnableDisable);
});
function CartButtonEnableDisable() {
let selOptA=$w("#checkboxGroup1").selectedIndices; console.log(selOptA)
let selOptB=$w("#checkboxGroup2").selectedIndices; console.log(selOptB)
if(selOptA.length + selOptB.length >= 6){
$w('#button1').enable();
} else $w('#button1').disable();
}