Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

End the setIntervall with clearIntervall

New Here ,
Nov 14, 2017 Nov 14, 2017

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);

}

TOPICS
Acrobat SDK and JavaScript
630
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 15, 2017 Nov 15, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2017 Nov 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2017 Nov 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 15, 2017 Nov 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2017 Nov 15, 2017
LATEST

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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines