I have received the value from the array then made a foreach to achieve each value from it. after adding each value to checkbox then made a onclick function to pass value to jquery function. i have receiving each value just one by one I need to collect all those value who has been selected from user by clicking on checkbox. Here is my code
$val = array();
$val = array("Peter"=>35, "Ben"=>37, "Joe"=>43);
foreach ($val as $value){
<input type="checkbox" id="vehicle1" name="vehicle1" value="<?php print_r($value['id']); ?>"
onclick="assignId(<?php echo (isset($value['id'])?$value['id']:'0') ?>)">
}
Here is my jquery function where I need to collect all checkbox selected record and pass to controller
function assignId(val) {
alert(val);
$.ajax({
url: '/path/to/file',
type: 'POST',
dataType: 'json',
data: {param1: 'value1'},
success : function(response){
alert(response);
}
});
}
As you can see, I just need to get all the selected value of the checkbox which is here under foreach and pass it to controller.
alert(val);???