I am new to programming and i am building a simple add-on for firefox but i am using web extensions, my options page has a few check box's
I need to save the values of these checkbox's and then restore them, Sample code is appreciated.
function saveOptions(e) {
e.preventDefault();
browser.storage.local.set({
box1: document.querySelector("#box1").checked
});
}
function restoreOptions() {
var getting = browser.storage.local.get("box1");
function setCurrentChoice(result) {
document.querySelector("#box1").checked = result.box1 || false
}
function onError(error) {
console.log(`Error: ${error}`);
}
getting.then(setCurrentChoice, onError);
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);
<form>
<p><label>Box1<input id="box1" type="checkbox" /></label></p>
<p><label>Box2<input id="box2" type="checkbox" /></label></p>
<p><label>Box3<input id="box3" type="checkbox" /></label></p>
<p><label>Box4<input id="box4" type="checkbox" /></label></p>
<p><label>Box5<input id="box5" type="checkbox" /></label></p>
<p><button type="submit">Save</button></p>
</form>
<script src="options.js"></script>
The code i got from Firefox's example works in saving value of one check box, but how do i save and restore all the values of different box ?