I have found several different methods for doing this online but for some reason i just cant get any of them to work for me, it may be they way im calling them or something but it also might involve my lack of expereince with JS but regardless I have decided to reach out.
here is the code i have found and so far is the only code that seems to give me a reaction on my page
$(":checkbox").on("change", function(){
var checkboxValues = {};
$(":checkbox").each(function(){
checkboxValues[this.id] = this.checked;
});
$.cookie('checkboxValues', checkboxValues, { expires: 7, path: '/' })
}
function repopulateCheckboxes(){
var checkboxValues = $.cookie('checkboxValues');
if(checkboxValues){
Object.keys(checkboxValues).forEach(function(element) {
var checked = checkboxValues[element];
$("#" + element).prop('checked', checked);
});
}
}
$.cookie.json = true;
repopulateFormELements();
This code will work im sure i just cant seem to get it to run right with the rest of my Javascript
here is my HTML, please don’t judge me on hideous code lol
<?php
$query=mysqli_query($con, "SELECT * FROM userprofile")or die(mysqli_error($con));
$rownumber= NULL;
while($row=mysqli_fetch_array($query)){
$rownumber++;
$id=$row['id'];
?>
<script type="text/javascript">
function checkOne<?php echo $id; ?>(){
if( document.getElementById('<?php echo $id; ?>').checked $$ document.getElementById('chkSelectDeselectAll').checked){
document.getElementById('chkSelectDeselectAll').checked = true;
}
else{
document.getElementById('chkSelectDeselectAll').checked = false;
}
}
</script>
<tr>
<td style="text-align:center;">
<input type="checkbox" id="<?php echo $rownumber; ?>" onclick="checkOne<?php echo $id; ?>()" name="selector[]" value="<?php echo $id; ?>">
</td>
<td><?php echo @$row['subscriber_acct_#'] ?></td>
<td><?php echo @$row['company_name_sos'] ?></td>
<td><?php echo @$row['username'] ?></td>
<td><?php echo @$row['contact'] ?></td>
<td><?php echo @$row['phone'] ?></td>
<td><?php echo @$row['name'] ?></td>
<td><?php echo @$row['account'] ?></td>
<td><?php echo @$row['repo_sale_date'] ?></td>
<td><?php echo @$row['num_of_prints'] ?></td>
<td><?php echo @$row['num_of_coversheets'] ?></td>
</tr>
<?php } ?>
this is how my row will output, i know my JS is suppose to affect every single checkbox on the page and then check to see if it has been checked and stored locally, and if not then set to false. But what its doing now is messing up my check all function by disabling it, and then stopping my ajax calls as well. Have i set this code snippet up incorrectly? or am i already doing something that messing with it instead?
here is my ajax call just for reference
function print_notice(){
// var note_text=$('#note_text').val();
// var cnotes=$('#cnotes').val();
// var formData = "note_text="+note_text+"&cnotes="+cnotes;
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
else {
throw new Error("Ajax is not supported by this browser");
}
var notice_data = $("#print_notice_form").serialize(); // gets all data from your form
$.ajax({
url : "http://localhost/xampp/process_notice/print_notice/mpdf/examples/print_notice.php",
type: "POST",
data: notice_data,
success: function(data, textStatus, jqXHR)
{
//data - response from server
alert(data);
// reloads page after user clicks ok on the response
location.reload(true);
},
});
}
Thank you all for the support and the assistence, I wish you the best :D