0

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/

user1
  • 347
  • 2
  • 12
  • 22

1 Answers1

4

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
Community
  • 1
  • 1
plalx
  • 42,889
  • 6
  • 74
  • 90