Page 1 of 1

How would I put an indicator on a page that's loaded with local storage variables and have it come back as marked one wa

Posted: Fri Oct 25, 2013 6:35 pm
by Jeff6301705

I want to have a radio button or a toggle that will stay in the listed array that shows either one or the other, but have it stay that way so when I come back to it, say a day later it's still marked with how I left it the last time I was there.


How would I put an indicator on a page that's loaded with local storage variables and have it come back as marked one wa

Posted: Fri Oct 25, 2013 7:08 pm
by Kateryna Grynko

Hi Jeff,

You would need to store the date: https://developer.mozilla.org/en-US/d...
You can store it in localStorage.


How would I put an indicator on a page that's loaded with local storage variables and have it come back as marked one wa

Posted: Fri Oct 25, 2013 7:52 pm
by Jeff6301705

If all the items are in string form how will that work, will I have to convert all my information into object to time them?


How would I put an indicator on a page that's loaded with local storage variables and have it come back as marked one wa

Posted: Fri Oct 25, 2013 8:58 pm
by Kateryna Grynko

Jeff,

You get current date:prenow = new Date().getTime();/pre
Save it as Last visit date, for example:prelocalStorage.setItem("lastEnter", now);/pre
When next visit, read it and subtract the current date from it:prevar lastEnter = localStorage.getItem("lastEnter");
var difference = new Date.getDate() - lastEnter;/pre
Now the difference between two dates in milliseconds is stored in 'difference' variable. You can convert it into days, dividing by (1000 60 60 * 24).