Kurt6863778
Posts: 0
Joined: Sun May 11, 2014 2:15 am

stop countdown timer

hey i have acountdown timer in my app and i want that when i press a button (named "btn_respond") within the appery app builder, that it stops the timer could some one please help me with this ? thanks in advance

oh by the way , it is set that when i click/press one button it starts to countdown until "0" fine, but i would like to press another button to stop it before it reaches "0"

here is the code that i have so far :

var count=10;

var counter=setInterval(timer, 1000); //1000 will run it every 1 second

function timer()
{
Appery("countdown").text(count);
count=count-1;
if (count ).show();

}
}

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

stop countdown timer

Hi Kurt.

You probably has some mistake in your code in following line:

precode

if (count ).show();

/code/pre

We have fix you code and here is result:

1 On start button event handler: http://prntscr.com/3otks3/direct

precode

var count=10;

//It will fix two clicks on the button.
clearInterval(window.countDownInterval);

window.countDownInterval = setInterval(timer, 1000); //1000 will run it every 1 second

function timer()
{
Appery("countdown").text(count);
count=count-1;

Code: Select all

 if(count < 0) 
     &#47;&#47;Stop interval&#46; 
     clearInterval(window&#46;countDownInterval); 

};

timer();

/code/pre

2 On stop button event handler: http://prntscr.com/3otkzk/direct

precode

&#47;&#47;It will fix two clicks on the button&#46;
clearInterval(window&#46;countDownInterval);

&#47;&#47;Please replace "Initial countdown value&#46;" with initial value you need&#46; Or remove this line if you don't want to change value to initial&#46;
Appery("countdown")&#46;text("Initial countdown value&#46;");

/code/pre

That's all.

Regards.

Kurt6863778
Posts: 0
Joined: Sun May 11, 2014 2:15 am

stop countdown timer

hey thanks alot !!

i have another problem

how do i compare one label's text/value of a radio button to another label's text by clicking a button and if they match display a message "correct"?

detailed information :

label 1 displays the text = "apple tree"

when user click a button...(after clicking an option of 3 radio buttons )

it should check if radio button value/text (pressed by user) matches label 1 and if so, display message " Correct"

thanks for help in advance

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

stop countdown timer

Kurt,

Add JS "click" event handler to your button and populate it with following code:

precode

&#47;&#47;Note you should replace "mobileradiogroup_5" with your mobileradiogroup component value&#46;
&#47;&#47;Get radio button selected value&#46;
var selectedValue = Apperyio("mobileradiogroup_5")&#46;find('input:checked')&#46;val();

&#47;&#47;Note you should replace "labelName" with your label component name&#46;
var labelText = Apperyio("labelName");

var isTheSame = selectedValue == labelText;

alert("isTheSame = " + isTheSame);

&#47;&#47;Here you can use this "isTheSame" variable as you need&#46;

/code/pre

Regards.

Kurt6863778
Posts: 0
Joined: Sun May 11, 2014 2:15 am

stop countdown timer

thanks again

Mike6979865
Posts: 0
Joined: Fri Jul 11, 2014 3:53 pm

stop countdown timer

I tried the code above to implement a countdown timer with a start button. I just need to implement a 5 minute counter. Please assist.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

stop countdown timer

Hi Mike,

Please specify more info about your requirements. Some screen shots will help.

Thanks.

Mike6979865
Posts: 0
Joined: Fri Jul 11, 2014 3:53 pm

stop countdown timer

I just need to implement a 5 minute countdown timer so when the user presses start the timer starts counting down, and it shows the count down, and then a sound will play after 5 minutes.

I created a button, and on button click I have this javascript code run:
var count=10;
//It will fix two clicks on the button.
clearInterval(window.countDownInterval);
window.countDownInterval = setInterval(timer, 1000); //1000 will run it every 1 second
function timer()
{
Appery("countdown_12").text(count);
count=count-1;
if(count < 0)
//Stop interval.
clearInterval(window.countDownInterval);
};
timer();

--
I also created a label and named it: countdown_12
--

When I press the button, nothing happens. I'm not sure how to code that. Your assistance will be highly appreciated.

Egor Kotov6832188
Posts: 0
Joined: Wed Nov 19, 2014 5:15 pm

stop countdown timer

Mike,

You are making mistakes in your code:
1) calling timer in setInterval function, when it is not defined
2) calling timer at the end, thus removing countdown right after setting it.

Mike6979865
Posts: 0
Joined: Fri Jul 11, 2014 3:53 pm

stop countdown timer

Can you please refer me to an example? I'm having difficulty with the countdown timer.

Return to “Issues”