Uncheck a checkbox if another checbox is checked

Hey,
Lets say that you have 4 checkboxes, you can use the following code:

$w.onReady(function () {
	for(let i=1 ; i < 5; i++){
		$w(`#checkbox${i}`).onChange(()=>{
			const checkBoxes = ['checkbox1', 'checkbox2', 'checkbox3', 'checkbox4'];
			let filtered = checkBoxes.filter(item => item !== `checkbox${i}`);
			filtered.forEach((checkbox)=>{ $w(`#${checkbox}`).checked = false; });
		});
	}
});

However, I recommend using for that purpose radio buttons which have the same functionality…

Good luck,
Tal.

1 Like