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")) : []; 

jsfiddler demo


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -