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

Auto Populate a Combo Box with Values from A Different Combo Box

scshaw
Registered: Apr 18 2009
Posts: 12
Answered

I have two date fields, the first is a START_DATE and the second is an END_DATE.
 
Both are combo box (drop down). In the Combo Box Properties, under the Options tab, the Item List for both fields contain the same values (only Wednesdays are listed formatted as 2011/04/27).
 
When a START_DATE value is selected by the user, I want the END_DATE field to be updated to the same value. This is easily done using the guidance on this site using Thom Parker's tutorial named Changing Another Field with Combo Box (Drop Down) Selection.
 
The question is, can the END_DATE field later be changed to a different date selected from the drop down list of END_DATE.

My Product Information:
Acrobat Pro 9.3, Macintosh
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
So the END_DATE field is being set from two sources, 1) a selection on the START_DATE field, and 2)user selection on the END_DATE field? Do you want to block changes from the START_DATE field after the user has made a selection on the END_DATE?

There are a couple of approaches to implementing this. One solution is to use a calculation script on END_DATE in combination with a state machine to ensure that the source is chosen properly. This approach is overly complex and has reliability issues.

The easiest and most reliable solution is to use the change or format events on START_DATE to set the value of END_DATE. The user can then make a selection on END_DATE without any interference, or odd event issues from the START_DATE field. The user can only use one control on the form at a time so they are either setting the value of START_DATE or END_DATE. With this implementation the action of setting the END_DATE is does not cause any scripting conflicts. But you have the problem of a START_DATE selection always overriding the END_DATE. There is a solution to this issue, Set a boolean variable when the user makes a selection on END_DATE, then use this variable to block the action from START_DATE.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

scshaw
Registered: Apr 18 2009
Posts: 12
Thom,

The easiest solution sounds correct.

The user will FIRST select the START_DATE from the START_DATE drop down list, which is usually also the END_DATE, but in some cases the END_DATE will be four or more weeks later (Wednesdays). In that case, the user will SECOND select a different END_DATE from the END_DATE drop down list.

So I do not want the START_DATE to override this SECOND choice if it is made by the user. What would that boolean variable look like and where do I put it?

scshaw


thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Accepted Answer
One simple way to block START_DATE from changing END_DATE is to only set END_Date if it is empty or the same as START_DATE.

For example, on the change (also called the keystroke) event of START_DATE

if(!event.willCommit)
{
var oEndFld = this.getField("END_DATE");
if((oEndFld.value == " ") || (oEndFld.value == event.value))
oEndFld.value = event.change;
}

The end value is tested for a non-selection " " and the previous START_DATE value. The non-selection is something you put in the list and it should be the first entry. It can be anything, for example it could be the words "Select End Date". Just as long as this is what is being tested. Also, if the last value set by the START_DATE matches the END_DATE, you can be reasonably certain that the END_DATE was set by START DATE.


Have you read this article?
http://acrobatusers.com/tutorials/2007/js_list_combo_livecycle/



Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

scshaw
Registered: Apr 18 2009
Posts: 12
I believe I have it now. This is similar to a method I already am using based on your article that I cited in the very first post of this question. The "non-selection" value is what does the trick!

Did not realize I was already doing what would work in this situation on another part of the form. Thank you, Thom.

I will read this new article also.
Mike J
Registered: May 3 2011
Posts: 2
I am trying to do something similar. I have one combo box with the names of departments and based upon the user selection of one of those departments I want to populate another combo box with the names of groups within those departments. There could be 20 group names for each department (only one department is selected). The solution has to be Acrobat only, I cannot use the LifeCycle application. Suggestions?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Read this article: Programming Lists

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Mike J
Registered: May 3 2011
Posts: 2
Thank you Thom, that was very helpful.