Im trying to send an array of checkboxes (value) to PHP via jquery. How can that be done?
See the following example:
<input type="checkbox" name="option[]" value="0"> Small
<input type="checkbox" name="option[]" value="1"> Medium
<input type="checkbox" name="option[]" value="2"> Large
<input type="checkbox" name="option[]" value="3"> X-Large
<input id="ButtonAdd" type="button" value="Add" />
jQuery code, couldn't get to work:
$("#ButtonAdd").click(function() {
var options = $("input:checkbox[name='option[]']");
$.post("ajax_extras.php", { options:options },
function(data) {
console.log(data)
});
});
ajax_extras.php file:
<?php
print_r($_POST['options']);
?>