Require at least one checkbox

3 replies · opened Apr 17, 2018

VvbastosApr 17, 2018

Hi,

I have a group of checkboxes which I would like to force the user to select at least one:

<input id="Monday" class="checkbox-style" name="days[]" type="checkbox" value="Monday">
<label for="Monday" class="checkbox-style-1-label checkbox-small">Monday</label>
<input id="Tuesday" class="checkbox-style" name="days[]" type="checkbox" value="Tuesday">
<label for="Tuesday" class="checkbox-style-1-label checkbox-small">Tuesday</label>
<input id="Wednesday" class="checkbox-style" name="days[]" type="checkbox" value="Wednesday">
<label for="Wednesday" class="checkbox-style-1-label checkbox-small">Wednesday</label>
<input id="Thursday" class="checkbox-style" name="days[]" type="checkbox" value="Thursday">
<label for="Thursday" class="checkbox-style-1-label checkbox-small">Thursday</label>
<input id="Friday" class="checkbox-style" name="days[]" type="checkbox" value="Friday">
<label for="Friday" class="checkbox-style-1-label checkbox-small">Friday</label>

How can I require at least one checkbox be true on the client side?

VvbastosMay 2, 2018

I noticed that other topics are being answered. Is it possible to get an response? Even if it is to tell me that you don't know?

Thank you.

SSemicolon WebSTAFFMay 3, 2018

Hello,

Thank You so much for your Patience!

Consider using the following HTML Code:


	
	Monday
	
	Tuesday
	
	Wednesday
	
	Thursday
	
	Friday
	

	Submit

and the following JS Code at the bottom of the Page after the js/functions.js JS Linking:


	$(document).ready(function () {
	    $('#form-checkbox').on( 'submit', function() {
	      checked = $("input[type=checkbox]:checked").length;

	      if(!checked) {
	        alert("You must check at least one checkbox.");
	        return false;
	      }

	    });
	});

This will definitely work fine. Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

VvbastosMay 4, 2018

OK great, thanks.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard