Snippet

JQuery obtient toutes les cases cochées

6 réponses de la communauté

var values=[];
$('input[name="your-checkbox-name[]"]:checked').each(function () {
  values[values.length] = (this.checked ? $(this).val() : "");
});
var selected = []; // New array
    $("#inputID input[type=checkbox]:checked").each(function () {
     selected.push(this.value);
});
var selected = [];
$('#checkboxes input:checked').each(function() {
    selected.push($(this).attr('name'));
});
$('input:checkbox').prop('checked', true);
<form id="form1" action="/controller/action" method="post">
   <input type="checkbox" name="box1" class="cBox" />
   <input type="checkbox" name="box2" class="cBox" />
   <input type="checkbox" name="box3" class="cBox" />
  <input type="submit" value="Submit" />
</form>
<script>
$('#form1').submit(function() {
   if ($('input:checkbox', this).length == $('input:checked', this).length ) {
            // everything's fine...
   } else {
            alert('Please tick all checkboxes!');
            return false;
   }
});
</script>
$('.theClass:checkbox:checked')