Reputation: 4523
I have Inputs
<input name="v[]" value="1" type="checkbox">
<input name="v[]" value="2" type="checkbox">
<input name="v[]" value="3" type="checkbox">
<input name="v[]" value="4" type="checkbox">
Where checked with this code
$(document).on('click',"tbody tr", function() {
if ($(this).hasClass('info')) {
$(this).removeClass('info');
$(this).find('input[name="v[]"]').prop('checked', false);
} else {
$(this).addClass('info');
$(this).find('input[name="v[]"]').prop('checked', true);
}
});
I want get array of checked Inputs with their values. How i can do it?
Thanks.
Upvotes: 0
Views: 112
Reputation: 8855
.serializeArray
should do it
$('input').on('click', function(){
console.log($('input').serializeArray());
});
Example of just getting inputs of type checkbox
http://jsfiddle.net/cbm4T/1/
$('input').on('click', function(){
console.log($('input[type=checkbox]').serializeArray());
});
Upvotes: 0
Reputation: 11807
var values = $.map($('input[name="v[]"]:checked'), function(obj) {
return $(obj).val();
});
edited: others beat me to it.
AND
if for some reason you wanted the reverse. checkboxes that are not clicked and their values.
var values = $.map($('input[name="v[]"]:not(:checked)'), function(obj) {
return $(obj).val();
});
Upvotes: 0