dimanche 24 mai 2015

Remembering a checkbox status in localstorage onload?

I'm building a Chrome Extension in which a user defaultly sees one div on load but can check checkboxes revealing (or hiding) other divs which I want to persist even after the page is closed.

My HTML is:

  <input id="click" type="checkbox"></input>
<div class="newnote">
<center><div class="note2">
    <img src="http://ift.tt/1Kt3ROO" draggable= "false"></div></center>
<center><div id = "content2">
<div id= "tcontent2" contenteditable="true" data-ph= " Make a note . . . "
style= "height: 300px; overflow: auto"></div>
</div></center>
</div>

<input id="clicktwo" type="checkbox"></input>
<div class="newnotetwo">
<center><div class="note3">
    <img src="http://ift.tt/1Kt3ROO" draggable= "false"></div></center>
<center><div id = "content3">
<div id= "tcontent3" contenteditable="true" data-ph= " Make a note . . . "
style= "height: 300px; overflow: auto"></div>
</div></center>
</div>  

and my JS is (currently only for 'clicktwo' checkbox):

function save(){
var checkbox = document.getElementById('clicktwo');
localStorage.setItem('clicktwo', checkbox.checked);
}

function load(){    
var checked = JSON.parse(localStorage.getItem('clicktwo'));
document.getElementById("clicktwo").checked = checked;
}

function wis(){
location.reload();
localStorage.clear()

}

My question is, why isn't this working? I've cross referenced a few sources but still find myself lost. Any and all help will be appreciated! Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire