Skip to main content
karstent46661207
Participant
November 14, 2017
Question

End the setIntervall with clearIntervall

  • November 14, 2017
  • 3 replies
  • 719 views

Hello,

I want to create a timer that pop-ups after a specific amount of time.

The User also should be able to stop the timer and the pop-ups. (by choosing between two Radio Buttons)

My problem is: the pop-ups never stop Can anyone help me? Thanks

var timer= 0;

var Feld = this.getField("Group3").value;

if (Feld == "1")

{

               function DoIt() {

                   app.alert("Sie müssen erst einen Wert eingeben!");}

                  timer = app.setInterval("DoIt()", 50000);

}

else

  {

                   app.alert("Gestoppt");

                   app.clearInterval(timer);

}

This topic has been closed for replies.

3 replies

Thom Parker
Community Expert
Community Expert
November 15, 2017

Also, timers are suspended when a modal dialog is displayed. 

Can you explain the ultimate goal? It really isn't practical to use an interval timer to continuously display alerts

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
karstent46661207
Participant
November 15, 2017

Hey. Thanks for the feedback.

It will be a document where the user has to enter a number every 5 minutes. Therefore I want to create a Pop-up to remind the user.
There also should be the posiibility to stop the pop-up  (for example when you are in a meeting ...).

Thanks for the support!

Thom Parker
Community Expert
Community Expert
November 15, 2017

You want to do something tricky. So you have to think through all the possibilities. For example, the alert box is modal, meaning it blocks anything else from happening until the user clicks on ok/cancel.  So what happens if the user doesn't click on anything. What happens if the user doesn't enter a number.  Is the time reset every 5 minutes, or when the user enters the number? What are all the specific actions that occur for all cases?  How exactly do you want all this to happen?

A better option might be to display a fake popup.  You can hide and show form fields. When done right, they look and act a lot like a modeless dialog. Then you could display dynamic data, such as the number of entries the user missed, and the amount of time that has elapsed since the last entry. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
Community Expert
Community Expert
November 15, 2017

Recursively calling the same timer is not a good idea.  Especially when it is an interval timer. Call the interval timer function once, and once only.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Legend
November 15, 2017

What runs this code (eg is this a validate event for Group3)?