lundi 1 octobre 2018

save and load Checkbox status across multiple devices

I am currently working on a project where I have to create a "website" that will only be launched on the intranet server of a company. So there is a user interface with 5 checkbox on it. Currently I am storing the checkbox status in the local storage like this:

<script>
var checkboxValues = JSON.parse(localStorage.getItem('checkboxValues')) || {},
    $checkboxes = $("#checkbox-container :checkbox");

        console.log(checkboxValues);
                
$checkboxes.on("change", function(){
  $checkboxes.each(function(){
    checkboxValues[this.id] = this.checked;
  });
  
  localStorage.setItem("checkboxValues", JSON.stringify(checkboxValues));
});

// On page load
$.each(checkboxValues, function(key, value) {
  $("#" + key).prop('checked', value);
});
</script>

This works fine so far! However now the problem I am struggling with for almost a week now:

The checkbox status have to be the same on every device... e.g if I am ticking a checkbox from one device the checkbox needs to be ticked by the next f5 on all other devices... I hope you guys can help me out and have some alternatives to store the checkbox status.

Thank you very much !

All the best

poza




Aucun commentaire:

Enregistrer un commentaire