mardi 15 septembre 2015

How to use localstorage to store all checkbox boolean values in a list to an array?

The code looks like this:

<div id="list">
  <input type="checkbox" id="1">
  <input type="checkbox" id="2">
  <input type="checkbox" id="3">
</div>

In another html pane (a separate template), I want to store all those checkbox (checked/unchecked) booleans into an array. What I did looks like:

var array = [];
var checkboxli = document.getElementsByTagName("input");
for (var i = 0; i < checkboxli.length; i++)
{
  array.push($("#input.prop('checked')"));
}

However, this doesn't work. I have other templates using tag name "input", so I need to limit the tag name to the ones under "#list" id (some sort of css selector perhaps). Currently, both document.getElementsByTagName("input") and $("#input.prop('checked')") won't work. There might be other syntax problems. Please help me resolve. Thanks.




Aucun commentaire:

Enregistrer un commentaire