lundi 3 octobre 2016

Localstorage: Save multiple session's checkbox status without overwritten

What I want to do is for the status of the checkbox be saved into localstorage when user click "submit" without overwriting the previous status. So the localstorage might have values like "true, false, false, true..." etc. At the moment my localstorage will overwrites the status of the checkbox if I submit the form in a new session.

JS:

document.addEventListener("deviceready",onDeviceReady,false);

function onDeviceReady() {
        document.getElementById("xbutton").addEventListener("click",savecheck,false); }
function savecheck(){
    var checkb = document.getElementById("MedA");
    localStorage.setItem("MedA", checkb.checked);
}

html:

<form>
        <div id='medA'>
            <input type="checkbox" id="MedA" name="Med" value="A">Medication A
         </div>
<input id="xbutton" type="button" onClick="savecheck()" value="Submit">
</form>




Aucun commentaire:

Enregistrer un commentaire