Expand my Community achievements bar.

Wait a specified period of time

Avatar

Level 3

I have a button on a form and when the user clicks it, I want to wait a specified number of seconds and then continue with a javascript.

What the best way to do this?

All suggestions appreciated.

4 Replies

Avatar

Former Community Member

Acrobat has a setTimeOut function that will execute an AcroForm command in the future. Here is the syntax for it:

var

test = app.setTimeOut("app.alert('This is a test....')", 2000);

The command needs to be an Acroform command and the 2000 is the time to wait (in milliseconds). You will not want to execute more than one command so you may want to put your script on an invisible button then execute like this:

var

test = app.setTimeOut("xfa.form.form1.Page1.Button2.execEvent('click')", 2000)

Note that all of your subforms in the path to the button must be named!

Paul

Avatar

Level 3

Thank you Paul, this is helpful.

With this command, my JS continues, and then the message appears, a specified time later.

I'm was looking for something that will allow the JS to pause for a specified period of time, for example, 10 seconds, and then continue.

Your help is appreciated.

Avatar

Former Community Member

That is the only thing I know of that will allow you to have some sort of timing of your script. Another unscientific way woudl be to create a loop and loop through it for some time. You coudl set your counter (the amount of times you loop) to a number that will make it sit there for 10 secs. This is unscientific and will change from machine to machine based on the clock speed, but you shoudl be able to get close to 10 secs anyways. Unless someone else has any ideas!

Paul

Avatar

Level 3

Getting close.... -)

I was thinking that I could grab the current time and store it in a variable (StartTime), then place the EndTime in a variable (StartTime + 10 Seconds).

I could then setup a do while loop (while time was < EndTime).

Because I'm new to this, I don't know how to go about it. Help is appreciated.