0

I did manage to save multiple data into localStorage, know I want to call all the data from localStorage to the form. Below is the code to save it into local storage

function save() {

// Parse any JSON previously stored in allEntries
var existingEntries = JSON.parse(localStorage.getItem("allEntries"));
if(existingEntries == null) existingEntries = [];
var date = document.getElementById("date").value;
var brakes = document.getElementById("brakes").value;
var chain = document.getElementById("chain").value;
var seats = document.getElementById("seats").value;
var handlebars = document.getElementById("handlebars").value;
var entry =
{
    "date": date,
    "brakes": brakes,
    "chain": chain,
    "seats": seats,
    "handlebars": handlebars
};
localStorage.setItem("entry", JSON.stringify(entry));
// Save allEntries back to local storage
existingEntries.push(entry);
localStorage.setItem("allEntries", JSON.stringify(existingEntries));

}

  • Does [this answer](http://stackoverflow.com/questions/8419354/get-html5-localstorage-keys) help ? The top voted answer also shows you how to get the value corresponding to the key – Tung Apr 28 '16 at 23:21

1 Answers1

1

you can get the values with this

var obj = JSON.parse(localStorage.getItem('entry'));

    document.getElementById("date").value = obj.date;
    document.getElementById("brakes").value = obj.brakes;
    document.getElementById("chain").value = obj.chain;
    document.getElementById("seats").value = obj.seats;
    document.getElementById("handlebars").value = obj.handlebars;
Rafael Mota
  • 127
  • 4