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
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:
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