TonyS
Posts: 0
Joined: Thu Jun 11, 2015 12:11 pm

Counting fun - using local storage to save a NUMERIC value

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?

TonyS
Posts: 0
Joined: Thu Jun 11, 2015 12:11 pm

Counting fun - using local storage to save a NUMERIC value

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?

TonyS
Posts: 0
Joined: Thu Jun 11, 2015 12:11 pm

Counting fun - using local storage to save a NUMERIC value

Page show is where you put alerts then not load?

TonyS
Posts: 0
Joined: Thu Jun 11, 2015 12:11 pm

Counting fun - using local storage to save a NUMERIC value

This is what fixed it:

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

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Counting fun - using local storage to save a NUMERIC value

Hello Tony,

Thank you for update. Glad it works :)

Return to “Issues”