Webflow Form. How can I make sure at least one of these checkboxes are ticked before a customer tries to send a form? I’m aware I can select ‘Required’, but the user may select more than one. If I select ‘Required’ on all of them, then they can’t send without ticking all of them!
If your form had an ID of myForm, and this code is in the before-/body section of the page, it will only permit submission if at least one checkbox is selected.
<script>
const form = document.getElementById('myForm');
form.addEventListener('submit', function (event) {
const checkboxes = form.querySelectorAll('input[type="checkbox"]');
const isChecked = Array.from(checkboxes).some(checkbox => checkbox.checked);
if (!isChecked) {
event.preventDefault(); // Prevent form submission
alert('Please select at least one option.');
}
});
</script>