Page 1 of 1

Counting fun - using local storage to save a NUMERIC value

Posted: Fri Jul 10, 2015 4:38 pm
by TonyS

I've spent this afternoon going round and round in circles.

I have a local storage variable called requestcount (set to a number, although from what I've read all numbers are stored as a string in local storage?)

So every time the user clicks a submit button I want to add 1 to the value of requestcount.

here's what I have that doesn't work:

var rc = parseInt(localStorage.getItem('requestcount'));
rc++;
localStorage.setItem('requestcount',rc)

Alert before moving to next page shows the correct incremental increase (say 3), however when I go to the next page and alert the localStorage variable I get 31???

So how does it work?


Counting fun - using local storage to save a NUMERIC value

Posted: Fri Jul 10, 2015 6:10 pm
by TonyS

Is this something peculiar to Appery? I return to the same page that initiated the addition and the alert that was there on load no longer fires?


Counting fun - using local storage to save a NUMERIC value

Posted: Fri Jul 10, 2015 6:14 pm
by TonyS

Page show is where you put alerts then not load?


Counting fun - using local storage to save a NUMERIC value

Posted: Fri Jul 10, 2015 6:16 pm
by TonyS

This is what fixed it:

var rc = +localStorage.getItem('requestcount');
rc++;
localStorage.setItem('requestcount',rc);
alert(localStorage.getItem('requestcount'));


Counting fun - using local storage to save a NUMERIC value

Posted: Sat Jul 11, 2015 2:00 am
by Alena Prykhodko

Hello Tony,

Thank you for update. Glad it works :)