Skip to main content
added 7 characters in body
Source Link
Luca Fagioli
  • 13.5k
  • 5
  • 64
  • 61

Unfortunately HTML5 does not provide an out-of-the-box way to do that.

However, using jQuery, you can easily control if a checkbox group has at least one checked element.

Consider the following DOM snippet:

<div class="checkbox-group required"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> </div> 

You can use this expression:

$('div.checkbox-group.required :checkbox:checked').length > 0 

which returns true if at least one element is checked. Based on that, you can implement your validation check.

Unfortunately HTML5 does not provide an out-of-the-box way to do that.

However, using jQuery, you can easily control if a checkbox group has at least one checked element.

Consider the following DOM snippet:

<div class="checkbox required"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> </div> 

You can use this expression:

$('div.checkbox.required :checkbox:checked').length > 0 

which returns true if at least one element is checked. Based on that, you can implement your validation check.

Unfortunately HTML5 does not provide an out-of-the-box way to do that.

However, using jQuery, you can easily control if a checkbox group has at least one checked element.

Consider the following DOM snippet:

<div class="checkbox-group required"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> </div> 

You can use this expression:

$('div.checkbox-group.required :checkbox:checked').length > 0 

which returns true if at least one element is checked. Based on that, you can implement your validation check.

added 7 characters in body
Source Link
Luca Fagioli
  • 13.5k
  • 5
  • 64
  • 61

Unfortunately HTML5 does not provide a standardan out-of-the-box way to do that.

HowwverHowever, using jQuery, you can easily checkcontrol if a checkbox group has at least one checked element. Consider

Consider the following DOM snippet:

<div class="checkbox required"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> </div> 

You can use the followingthis expression:

$('div.checkbox.required :checkbox:checked').length > 0 

which returns truetrue if at least one element is checked. Based on that, you can implement your validation check.

Unfortunately HTML5 does not provide a standard way to do that.

Howwver, using jQuery, you can easily check if a checkbox group has at least one checked element. Consider the following DOM snippet:

<div class="checkbox required"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> </div> 

You can use the following:

$('div.checkbox.required :checkbox:checked').length > 0 

which returns true if at least one element is checked. Based on that, you can implement your validation check.

Unfortunately HTML5 does not provide an out-of-the-box way to do that.

However, using jQuery, you can easily control if a checkbox group has at least one checked element.

Consider the following DOM snippet:

<div class="checkbox required"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> </div> 

You can use this expression:

$('div.checkbox.required :checkbox:checked').length > 0 

which returns true if at least one element is checked. Based on that, you can implement your validation check.

added 64 characters in body
Source Link
Luca Fagioli
  • 13.5k
  • 5
  • 64
  • 61

Unfortunately HTML5 does not provide a standard way to do that.

UsingHowwver, using jQuery, you can easily check if a checkbox group has at least one checked element. Consider the following DOM snippet:

<div class="checkbox required"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> </div> 

You can use the following:

$('div.checkbox.required :checkbox:checked').length > 0 

which returns true if at least one element is checked. Based on that, you can implement your validation check.

Unfortunately HTML5 does not provide a standard way to do that.

Using jQuery, you can easily check if a checkbox group has at least one checked element. Consider the following DOM snippet:

<div class="checkbox required"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> </div> 

You can use the following:

$('div.checkbox.required :checkbox:checked').length > 0 

which returns true if at least one element is checked.

Unfortunately HTML5 does not provide a standard way to do that.

Howwver, using jQuery, you can easily check if a checkbox group has at least one checked element. Consider the following DOM snippet:

<div class="checkbox required"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> <input type="checkbox" name="checkbox_name[]"> </div> 

You can use the following:

$('div.checkbox.required :checkbox:checked').length > 0 

which returns true if at least one element is checked. Based on that, you can implement your validation check.

Source Link
Luca Fagioli
  • 13.5k
  • 5
  • 64
  • 61
Loading