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

Acrobat Javascript, How do you reset a timer?

Community Beginner ,
Jun 09, 2023 Jun 09, 2023

My script is this:

 

this.getField("TextField").display = display.visible;

app.setTimeOut ('this.getField("TextField").display = display.hidden;', 9000 );

 

This works fine as it will show the text field and hide it after 9 seconds.  But if a user spams the button it does not work so well. 

 

Is there a way to reset the timer if someone spams the button?

TOPICS
How to , JavaScript , PDF
1.2K
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
1 ACCEPTED SOLUTION
Community Expert ,
Jun 10, 2023 Jun 10, 2023

Yes, this is possible, and is explained in the samples of the setTimeOut method.

Here's an example:

 

if (timer1!=null) app.clearTimeOut(timer1);
timer1 = app.setTimeOut('this.getField("TextField").display = display.hidden;', 9000 );

View solution in original post

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 ,
Jun 09, 2023 Jun 09, 2023

What does you mean with "spams the button" ?

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 Beginner ,
Jun 10, 2023 Jun 10, 2023

By "spams the button" I mean if the user rapidly and repeatedly clicks on the button. 

For instance, if a user rapidly pressed the button 10 times, my script will just keep adding 9 seconds 10 times. 

I would like the timer to reset if someone presses the button while the timer is still going.

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 ,
Jun 10, 2023 Jun 10, 2023

You can hide the button.

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 Beginner ,
Jun 10, 2023 Jun 10, 2023

Good idea, thank you sir!

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 ,
Jun 10, 2023 Jun 10, 2023

Yes, this is possible, and is explained in the samples of the setTimeOut method.

Here's an example:

 

if (timer1!=null) app.clearTimeOut(timer1);
timer1 = app.setTimeOut('this.getField("TextField").display = display.hidden;', 9000 );

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 Beginner ,
Jun 10, 2023 Jun 10, 2023

You're a genius!  This exactly answers my question.  Thank you so much!

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 Beginner ,
Jun 10, 2023 Jun 10, 2023

When I closed out the PDF and reopen it, it seems to get a javascript error that timer1 is not defined.  Any insight on why?

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 ,
Jun 10, 2023 Jun 10, 2023

Add a doc-level script with this code:

 

var timer1;

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 Beginner ,
Jun 10, 2023 Jun 10, 2023
LATEST

Thank you

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