So I am making a site with a custom form which has 5 checkboxes. I need a minimum of 2 but maximum of 3 boxes checked., ids checkbox1,2 and so on.
I am relatively new to coding on wix but I figured I have to work with the onChange function, setup a counter to count the number of checkboxes already ticked and whenever a new one is checked the counter increases. idk how to put this all in place. any help is appreciated really.
Thank you so much for taking the time to read this.
Hi,
Connect the checkboxes to the same onchange event function.
The function should look something like this:
export function checkbox1_change(event, $w) {
let counterOfChecked = 0;
let idOFUnChecked = [];
for (let i = 1; i < 6; i++) {
if ($w(`#checkbox${i}`).checked) {
counterOfChecked++;
} else {
idOFUnChecked.push(i);
}
}
if (idOFUnChecked.length === 2) {
idOFUnChecked.forEach((id) => {
$w(`#checkbox${id}`).disable();
});
} else {
idOFUnChecked.forEach((id) => {
$w(`#checkbox${id}`).enable();
});
}
}
Please update in your progress.
Roi.
Hi Roi,
I am working of same king of problem.
Can You please elaborate how to do this:
Connect the checkboxes to the same onchange event function.
how to connect the checkboxes to same onchange function - do i have to set the property of all checkbox to onchange or something else …BTW i understand the code but this part is not cleared. …Please Guide me .
Hi,
Check out this article .
Roi.