html - Localstorage can't generate data Javascript -
i want generate new div
element information input
, not working correctly. have big problem saving , receiving data localstorage
. spent 2 days researching issue. kind tell me problems?
fiddle: https://jsfiddle.net/v5r653nd/1/
var nameaaaa = document.getelementbyid("nameofbook"); var author = document.getelementbyid("nameofauthor"); var year = document.getelementbyid("year"); function makejob() { testobjects.push({ name: nameaaaa.value, author: author.value, year: year.value }) localstorage.setitem('testobjects', json.stringify(testobjects));
if understood correctly problem, overwritting localstorage since @ start of script declare testobject empty array , later work on , replace localstorage values.
so should retrieve localstorage value first , store in variable:
var testobjects = localstorage.getitem("testobjects") ? json.parse(localstorage.getitem("testobjects")) : [];
Comments
Post a Comment