These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Adding a Countdown timer from Time field to livecycle form

Michelle Graham
Registered: Nov 16 2010
Posts: 6
Answered

I have created a form in adobe livecycle and I would like to add a Countdown timer that clicks off when a user enter's a time. I need the countdown timer to be 2 hours from the entered time. The user will have 2 hours to complete the form. I need warning boxes that will pop up at 30 minutes and at 15 minutes. If not completed in the 2 hour time frame from when the time was entered then the form will prompt to close.
I have found where the timer starts from the start or stop button but I would like it to start from when the time field is excited.
I am new to form scripting and any help would be greatly appreciated.
Thank you

Michelle Graham

My Product Information:
LiveCycle Designer, Windows
DaveyB
Registered: Dec 10 2010
Posts: 70
Hi Michelle!

While a full purpose-built application could make use of multi-threading to do what you need, this is more difficult to achieve in javascript. The quick-and-dirty method will get the job done though.

I'm guessing that this is some sort of test paper with a 2 hour limit, and which needs to be either printed, saved or emailed at the end of the allotted period. My immediate thought is that there are several ways around this timer - re-opening the document will reset the timer for example, however, on to your questions.

To set exiting the time field as the "start" button for the timer, simply take the code from the on-click event for the start button and copy it into the exit event for the field. Exiting the field will now do the same as clicking the start button. This approach does have its drawbacks though, since the candidate could enter a non-time string which would prevent the timer from functioning if correct validation is not followed.

My preference would be to use the on-click of the start button to start the timer and simultaneously populate the time field with the current time, non-editable. This then gives you a storage place for your start time, and you could place this into the document header so that it appears on each page as a reminder to the candidate!

Create a javascript function to compare current time against the stored start time, and use statements in this function to test and execute the desired parameters. You can then place this function call into the entry and exit events on each field in the document. While this may sound like a formidable task, changing the code on every field, it really only needs to be done once for each field type (text field, numeric field, date field, checkbox, etc.), then copy that field and simply change its field-name to the correct name of the pasted field.

This method means that the time remaining will be checked every time the candidate moves to a new field or clicks the mouse outside a field. (I did say "quick-and-dirty"!). This function should be loaded into the form globals list so that it can be called from anywhere on the form.

For ease of changes, I would create a form variable tTimeAllowed which is set to 2 hours. This way, if more questions are added to or removed from the form and the time limit is changed, you only need to make that change in one single place and without having to delve into the code to do it. You can also hard code it into the code if you so wish!

Take a look at the Time Between Times Calculator and "view source" to look at the coding. Create the script so as to set the time remaining into a variable. The rest of the function is simply a switch statement pointing to your various requirements. For example:
function fCheckTimeRemaining() {tTimeLeft = // code to determine the remaining time in minutesif (tTimeLeft < tTimeAllowed){// execute code to lock all fields in the document as non-editable; else {switch (tTimeLeft) {case <30 :if (nWarn30 = 0){//code to pop up 30 min msg and set nWarn30 to value 1 }  // end if statementcase <15 :if (nWarn15 = 0){//code to pop up 15 min msg and set nWarn15 to value 1}  // end if statement}  // end switch statement}  // end if statement}  // end function
Fairly rudimentary code, but it covers your objectives as outlined. Note that nWarn30 and nWarn15 should be hidden numeric fields on the form, set to global scope and with an initial value of 0. They are simply used to check to see if the 30 and 15 minute messages have already been displayed.

Hope that helps you out some!

D

LiveCycle Designer 8.0
"Genius is one percent inspiration, ninety-nine percent perspiration." ~~ Thomas Edison
"If at first you don't succeed, get a bigger hammer." ~~ Alan Lewis
"If the conventional doesn't work, try the unconventional" ~~ DaveyB

Michelle Graham
Registered: Nov 16 2010
Posts: 6
The timer is actually for an alarm that has gone off and I have to depend on the user to put in the correct time. They have two hours to complete the form from when the alarm went off not from when the form was opened. So I would like a field that displays a countdown timer, so if they entered 2:30pm and its 3:00pm right now a 90 minute countdown timer would start in the designated field. Is this possible. I am creating a few forms and this is one of the only ones with a timer.

Michelle Graham

DaveyB
Registered: Dec 10 2010
Posts: 70
Accepted Answer
OK, now I see what you're looking for, sorry for the misunderstanding. There is a tutorial on this site that covers this, and includes a downloadable working PDF that you can open up to examine the scripts used - including the milliseconds in the countdown might be a little OTT, but it would help instill a sense of urgency in the user. I found this tutorial very helpful on one of my own projects, and hopefully it will clear some things up for you too!The 3rd paragraph in my rather garrulous post above outlines the steps for setting the timer start to the exit event for the field.

As for the freeform time entry in the field, it is simple enough to calculate the remaining time on the timer based off the user entered time and the current time. Use a document properties variable to define the length of the timer (in this case, 2 hours), and be sure to reference that variable in the field validation to ensure that an out of range time cannot be entered. In other words they can't enter a time that is >CurrentTime or is <(CurrentTime - TimerLimit). I would use the initialize event of the form to prepopulate the field with the current time and let them change it, since having an example already in the field will help them enter the time in the required format.Hope that helps!

DaveyB

LiveCycle Designer 8.0
"Genius is one percent inspiration, ninety-nine percent perspiration." ~~ Thomas Edison
"If at first you don't succeed, get a bigger hammer." ~~ Alan Lewis
"If the conventional doesn't work, try the unconventional" ~~ DaveyB

Michelle Graham
Registered: Nov 16 2010
Posts: 6
I need some help. I have my form where it will calculate the time the form needs to be completed by.
How can I pop up a message box for when the system time gets 30 minutes within the calculated to be completed by field?
here is my form calc for the calculation
Offset is the control room time and the system time different.
The entry time is when the alarm sounded, so the user has two hours to complete the form from when the alarm sounded, but since the control room time and the computers system time are not synced an offset is used.

if (OffSet==null)
then null
else
var start = Time2Num(EntryTime, "HH:MM")
var timer = 7200000
var offset = OffSet.rawValue * 60 * 1000
var finish = start + offset + timer
$ = Num2Time(finish, "HH:MM")
endif



I want a countdown timer to countdown to the to be completed by time, which is above and host messages when the user gets with 30 minutes of the time

I have a hidden field to try for the message box but cant get it to work


if (OffSet==null)
then null
else
var finish = Time2Num(FinishTime, "HH:MM")
var timer = 3600000
var warn60 = finish - timer
$ = Num2Time(warn60, "HH:MM")
endif



Michelle Graham