javascript - LocalStorage and JSON.stringify JSON.parse -


i have been working on project allows user submit memories place have visited , tracks location of when memory submitted. problem trying use localstorage app, read json.stringify , json.parse, , don't understand how use them in code yet.

this form.js processes form , grabs text fields. clears form when add button(on display details page) or enter details button clicked. receives information , sends out message window.

function processform(){  var locate = document.myform.locate.value; var details = document.myform.details.value; var storedata = [];  localstorage.setitem("locate", json.stringify(locate)); localstorage.setitem("details", json.stringify(details)); alert("saved: " + localstorage.getitem("locate") + ", , " + localstorage.getitem("details"));  var date = new date,     day = date.getdate(),     month = date.getmonth() + 1,     year = date.getfullyear(),     hour = date.gethours(),     minute = date.getminutes(),     ampm = hour > 12 ? "pm" : "am";         hour = hour % 12;     hour = hour ? hour : 12; // 0 = 12     minute = minute > 9 ? minute : "0" + minute;     hour = hour > 9 ? hour : "0" + hour;      date = month + "/" + day + "/" + year + " " + hour + ":" + minute +  " " + ampm;  localstorage.setitem("date", json.stringify(date));  storedata.push(locate, details, date); localstorage.setitem("storedata", json.stringify(storedata));    }  function clearform(){ $('#myform').get(0).reset(); }  function retrieveforminfo(){  var data = json.parse(localstorage.getitem("storedata"));     var locate = json.parse(localstorage.getitem("locate")); $("#locate2").html("place: " + locate);  var details = json.parse(localstorage.getitem("details")); $("#details2").html("description: " + details);  var date = json.parse(localstorage.getitem("date")); $("#date").html(date);  } 

but major problem running know how take information in correctly using json.stringify , json.parse , appending window html elements dynamically, list of memories.

any appreciated!

var printstoragebody = function(){     $("body").html("");     $("<pre></pre>").appendto("body");     $("pre").html("\r\n" + json.stringify(localstorage).replace(/","/g , "\r\n").replace("{ ", "").replace(" }","") + "\r\n"); }; 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -