Page 1 of 1

display counter on screen and store count

Posted: Sun Jun 08, 2014 1:59 am
by KarenW

Hi I'm new to appery .
I want a user to be able to have a user press a button and have it count the number of times it has been pressed. I want this displayed on the screen next to the button - like a counter. I also want to store the total count. What is the easiest way to achieve this please
cheers
Karen


display counter on screen and store count

Posted: Sun Jun 08, 2014 4:37 am
by Illya Stepanov

Hi Karen,

You can achieve this using JavaScript with jQuery, this is one of the ways:
Let's assume you have the Label component and the Button on your page - on button click event add this JS:
precode
Apperyio('your_label').text( function(i, val) { return +val+1; });
// this will return value iteration inside the label each time you click the button
/code/pre
On another button you can store the final cont value inside the local storage variable, on button click event add this JS:
precode
var counts = Apperyio('your_label').text();
// here we put the current value inside the label component in variable 'counts'
// and store this value inside the local storage variable for later usage in your app
localStorage.setItem('total_counter', counts);
/code/pre


display counter on screen and store count

Posted: Sun Jun 15, 2014 7:53 am
by KarenW

hi thanks
I have no idea about jquery but ill give it a go
thanks