I have checkboxes that are generated dynamically with value from database in a while statement as such :
while($getplands = mysqli_fetch_assoc($getplanresults)){
<tr>
<td><input class="thisinput" type="checkbox" value="'.$getplands['id'].'"></td>
</tr>
}
When the user clicks on a checkbox two things must happen
data is sent to ajax and callback response displayed in a div
the checkbox is checked
If I'm using below code, the checkbox does not check but I'm able to fetch data from database with ajax and display user choice.
$('.thisinput').click(function(e){//a checkbox is checked
$(this).prop('checked', true);//does not work here
$.ajax({//works here
type: 'POST',
url: 'fetch.php',
data:values,
dataType: 'json',
success: function(datas)
{
$('#mychoice > tbody:last').append(datas.mychoice);
}
});
});
If I'm using below code the checkbox is checked but I'm unable to fetch data from database with ajax and display user choice.
$('.thisinput').on('change', 'input:checkbox', function(){
$(this).prop('checked', true);//works here
$.ajax({//does not work here
type: 'POST',
url: 'fetch.php',
data:values,
dataType: 'json',
success: function(datas)
{
$('#mychoice > tbody:last').append(datas.mychoice);
}
});
});