Skip to content
How to retrieve value from multiple checkbox You are here:
Home Snippet How to retrieve value from…
Home »
Snippets » How to retrieve value from multiple checkbox
How to retrieve value from multiple checkbox
Retrieving data from multiple checkbox option can sometimes a little tricky. This simple code snippet will help listen your work load using jquery.
//select all checkboxes
$("#select-all").change( function(){
var status = this.checked;
$('.shipment-options').each( function(){
this.checked = status;
});
});
$('.shipment-options').change(function(){
//uncheck "select all", if one of the listed checkbox item is unchecked
if(this.checked == false){
$("#select-all")[0].checked = false;
}
//check "select all" if all checkbox items are checked
if ($('.shipment-options:checked').length == $('.shipment-options').length ){
$("#select-all")[0].checked = true;
}
});
$('#get-data').on('click', function(){
var persons = [];
$('.shipment-options').each(function(i){
if( $(this).prop('checked') ){
persons.push( $(this).val() ) ;
return;
}
});
alert( persons );
console.log( persons );
});
Go to Top
Marked Crafts
X
MASCO
X
Crafties
X
Warhawk Esports
X
Aldra
X
Physique
X
Quantic Online
X
Carnvalley
X We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. Ok Reject Privacy policy