Currently, I am troubleshooting a script that is intended to keep checkbox values checked even after the page is reloaded or refreshed. The code snippet below was implemented for this purpose, but unfortunately, it doesn't seem to be functioning correctly. Any assistance in resolving this issue would be highly appreciated.
<script>
function onClickBox() {
let checked=$("#check").is(":checked");
localStorage.setItem("checked", checked);
}
function onReady() {
let checked="true"==localStorage.getItem("checked");
$("#check").prop('checked', checked);
$("#check").click(onClickBox);
}
$(document).ready(onReady);
</script>
The following line of code
return '<input type="checkbox" id="check" href="#"' + 'order_id="' + data + '">Yes</>';
allows an admin user to select a checkbox. Subsequently, the code captures the ID and triggers the execution of check_payment.php where a query inserts "yes" into the specified ID row.
aoColumnDefs: [
{
aTargets: [6],
mData: "userId",
mRender: function (data, type, full) {
return '<input type="checkbox" id="check" href="#"' + 'order_id="' + data + '">Yes</>';
//return '<button href="#"' + 'order_id="'+ data + '">Yes</button>';
}
}
],
language: {
url: 'https://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/English.json'
}
});
$('#example').on( 'click', 'input:checkbox', function () {
var data = table.row( $(this).parents('tr') ).data();
var order_id = data['order_id'];
console.log(order_id);
$.ajax({
type: "POST",
url: 'check_payment.php',
data: "order_id=" + order_id,
});
} );