I have a group of checkboxes that I’m trying to pass through POST via AJAX/PHP. When I fill the array it’s only picking up the last one.
HTML
<input type="checkbox" name="committee[]" value="membership">Membership <br/>
<input type="checkbox" name="committee[]" value="operations">Operations <br/>
<input type="checkbox" name="committee[]" value="membership">Board <br/>
Javascript
$("#save").click(function (e) {
...
var committee = { 'committee[]' : []};
$('input:checked').each(function(){
committee['committee[]'].push($(this).val());
});
$.ajax({
url: 'save.php',
type: 'POST',
data: {
...
committee: committee
}
});
});
On the save.php all I’m doing at this point is print_r($_POST); and seeing that only the last checked box shows up. I know it’s something I’m doing wrong in the input:checked function, but I’m not sure what.
That array index with “[]” probably causes problems. Do this instead: