Reputation: 53
How do i create an array from an unknown number of checkboxes, adding the values to the array using jquery? and then posting the array?
Upvotes: 1
Views: 92
Reputation: 28995
var arr = $.map($('input[type="checkbox"]:checked'),function(checkbox){
return checkbox.value;
})
Upvotes: 1
Reputation: 148
You can try this:
function updateTextArea() {
var allVals = [];
$('#c_b :checked').each(function() {
allVals.push($(this).val());
});
$('#t').val(allVals)
}
$(function() {
$('#c_b input').click(updateTextArea);
updateTextArea();
});
Upvotes: 1