Monday, August 20, 2012

php – jquery array of checkboxes contains the last one checked

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.






Rating: 5 out of 5 based on 3 ratings



The post php – jquery array of checkboxes contains the last one checked appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/php-jquery-array-of-checkboxes-contains-the-last-one-checked.html

No comments:

Post a Comment