So I've got this code that saves around 30 checkbox selections to local storage, which is working fine. Then there's this separate checkbox below, when checked it automatically reloads the page:
<input type="checkbox" id="autoload" class="autoload"> Tick this box if you want to automatically update the results as you choose them from the options below.
And here's the code to trigger the page reload:
if ($('#autoload').is(':checked')) {
location.reload();
}
In addition, this is the code snippet where the checkboxes are saved to local storage, and where I need to insert the above reload trigger:
window.onload = function() {
function onClickBox() {
var arr = $('.box').map(function() {
return this.checked;
}).get();
localStorage.setItem("checked", JSON.stringify(arr));
}
$(document).ready(function() {
var arr = JSON.parse(localStorage.getItem('checked')) || [];
arr.forEach(function(checked, i) {
$('.box').eq(i).prop('checked', checked);
});
$(".box").click(onClickBox);
// Need to add the trigger page reload code here
});
}
I'm struggling with figuring out how and where to place the code for triggering page reload in the existing script mentioned above. Any assistance would be greatly appreciated!