I’m trying to change a value inside localstorage. This item is the status of a checkbox. I want, everytime that a checkbox is checked to set the value to true or false of that checkbox. I tried many ways until I realized that there is no way you can change a value without using JSON.
To add the value I use:
localStorage.setItem("status-" + i, $status.is(":checked"));
and to delete I use:
var parentId = $this.parent().attr('id');
localStorage.removeItem("'" + parentId + "'");
Now to change the value I tried:
$itemList.delegate("#status-" + i, 'click', function(e) {
var $this = $(this);
var parentId = this.parent().attr('id');
if ($this.is(":checked")) {
localStorage.setItem("'" + parentId + "'".val("fdgsdagf"));
// Note that alert here works.
}
});
This is how my local storage looks like:

I hope someone could help me. I’ve been working on it for few days…
Here is a fiddle for it: http://jsfiddle.net/CC5Vw/7/
Thanks alot
look at this: http://jsfiddle.net/Rh4Au/6/ works well..
changes http://jsfiddle.net/CC5Vw/7/ to http://jsfiddle.net/Rh4Au/6/
line 30:
+ "<div class='checkbox'><input type='checkbox' class='test' id='status-" +i+ "'></div>"ichaged tojbecause i is the length and j is the iterator.insertion after line 34:
The code loads the data from
localStorageand check in the checked checkboxes.The
tempasdis a temporary variable store the current ID num of the checkbox (because they not always come ascending.changes from line 99 to 117:
to
i need the loop because it needs to delegate an event to each checkbox, and also the event must set the
localStoragetofalsewhen it gets unchecked.btw the
.parent().parent()is unnecesarry now because i fixed at line 30.