Reputation: 357
Wanting to be able to have multiple people take a survey then refresh etc. Anyway to store multiple keys to local storage without overwriting the previous? Group by a userID or sorts?
$('form').submit(function() {
$('input, select, textarea').each(function() {
var value = $(this).val(),
name = $(this).attr('name');
localStorage[name] = value;
console.log('stored key: '+name+' stored value: '+value);
});
});
project in whole: http://jsfiddle.net/PVGUq/
Upvotes: 0
Views: 5612
Reputation: 43718
You can store JSON instead of plain text. For the maximum storage size see What is the max size of localStorage values?
var items = [1, 2, 3, 4];
localStorage.setItem('myKey', JSON.stringify(items));
items = JSON.parse(localStorage.getItem('myKey'));
items.length; //4
Upvotes: 4