basically,
im trying to store the values of checkboxes that are checked, and then later retrieve them on another page using localstorage.
at the moment, it stores the checkbox value of the one clicked at the time, but i want to stored all checkboxes that are checked, not just one.
so currently it only stores one, rather than all checkboxes checked.
heres my code.
$("input[type=checkbox]").on('change', (event) => {
let $newval = [];
let $this = $(event.currentTarget);
let $label = $(`.visible[for=${$this.attr('id')}]`);
if ($this.prop("checked")) {
$label.text("Item selected");
// localStorage.setItem("checkbox", $(this).val());
let $newval = (event.target.value);
let picked = JSON.stringify($newval);
var selectedGameIds = localStorage.setItem("selectedGameIds", picked);
console.log($newval);
console.log(event.target.value);
} else {
$label.text("Compare");
}
console.log($("input[type=checkbox]"));
if ($('input[type=checkbox]:checked').length >= 3) {
$("input[type=checkbox]:not(:checked)").prop("disabled", true);
} else {
$("input[type=checkbox]").prop("disabled", false);
}
})
attempted it with a for loop earlier, didn't really work out. wondering if theres a more simple solution. regards