I need to send the values of the checkboxes in a page to a php page that will process this data and return a response in a <div> called result. This must get a response everytime a checkbox is checked or unchecked so the ajax call should work "live" for all the checkboxes in the page.
I've tried all the examples found on SO, but without success so there must be something wrong in what I'm doing but I'm unable to find what.
This is one of the checkbox (all the checkboxes are similar)
echo "<input type='checkbox' id='model' class='model' value='" . $row["model"] . "'>" . $row["model"] . "<br>";
The following is the jquery I've tried
$("checkbox").click(function() {
if(this.checked){
$.ajax({
type: "POST",
url: 'pfinder.php',
data: $(this).attr('value'),
success: function(data) {
$("#result").load(result);
},
});
}
};
I've also tried to use just the id of a single checkbox, just to test, but unsuccessfully
$("#model").click(function() {
if(this.checked){
$.ajax({
type: "POST",
url: 'pfinder.php',
data: $(this).attr('value'),
success: function(data) {
$("#result").load(result);
},
});
}
};
And the following is pfinder.php that process the data
$model = $_POST["model"];
echo $model;
very basic, but so far, no data is showed in the
<div id='result'>
Any advice?
$(this).val()orthis.value