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

Populate combo box

julie12
Registered: Oct 25 2010
Posts: 4
Answered

Hi,
 
How do I populate one combo box, based on the value of another?
 
Example:
- Combo Box 1 gives a list of provinces.
 
- Based on which province is selected, Combo Box 2 would display a list of cities specific to the selected province.
 
I'm working in Adobe Acrobat 9 standard.
 
Thanks.

My Product Information:
Acrobat Standard 9.3.1, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Read this tutorial: http://acrobatusers.com/tutorials/2007/js_list_combo_livecycle/

and post again if you get stuck.
julie12
Registered: Oct 25 2010
Posts: 4
Thanks - the article is exactly what I need. However, how do I access the area to enter code (either AcroForm or LiveCycle)? Are they available in Adobe 9 standard?
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
With Acrobat Standard, there is unfortunately no user interface for creating document-level JavaScripts, which is a stupid restriction. You can, however, place the code in the initial page's "Page Open" event. To access it, open the "Pages" navigation pane, right-click on the initial page of the PDF and select "Page Properties > Actions". Then select the "Page Open" trigger and select an action of "Run a JavaScript", and add a new one. Place the code in the JavaScript editor that then gets shown.Code in a Page Open event will execute when the page is opened, making any variables and functions available to any code that may use them thereafter. This is much like code in document-level JavaScripts that executes when the document is opened.

Since LiveCycle Designer isn't included with Acrobat Standard, you can disregard it.
julie12
Registered: Oct 25 2010
Posts: 4
Thank you, that worked. However, I'm unable to see the code provided in the example AcroForm.

If there isn't a way to see this code, could you please take a look at the following code in my PageOpen trigger and let me know why the second combo box isn't being populated? My two questions are embedded in the below code:

//Q1. Does naming matter here? ProvinceOfTest is the same name as the combo box on the form. The Province entries in the ProvinceOfTest combo box also align.

var ProvinceOfTest = {
"British Columbia": [
["Vancouver"], ["Whistler"]
],
"Alberta": [
["Calgary"],["Edmonton"],["Red Deer"]
],
"Saskatchewan": [
["Hicksville"]
],
};

//Q2. I am unsure where to use these variables?

var BCItems = ProvinceOfTest["British Columbia"];
var ABItems = ProvinceOfTest["Alberta"];
var SKItems = ProvinceOfTest["Saskatchewan"];

//Comment: This function is called from the custom keystroke script in the first Combo Box, "ProvinceOfTest". Te CityOfService is the name of the second combo box on the form.

function SetCityEntries()
{
if(event.willCommit)
{
var lst = ProvinceOfTest[event.value];
if( (lst != null) && (lst.length > 0) )
this.getField("CityOfService").setItems(lst);
else
this.getField("CityOfService").clearItems();
}
}


George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Good job. Your code works for me, but note that you should save your changes, close the document, and re-open it. Alternatively, if there is more than one page, simply go to another page and return. Does it work now?

Regarding the following:

var BCItems = ProvinceOfTest["British Columbia"];
var ABItems = ProvinceOfTest["Alberta"];
var SKItems = ProvinceOfTest["Saskatchewan"];

These are not needed as far as I can tell. I haven't gone and reviewed the tutorial to see how something similar is used.

With Standard, you will not be able to review code of any examples that is placed in a document-level JavaScript, due to Standard's silly limitation.

Also, I would suggest the following code style changes. Unfortunately, this forum is antagonistic towards code postings, so the indentation is missing. I hope you get the idea.

function SetCityEntries() {

if (event.willCommit) {

var lst = ProvinceOfTest[event.value];

if (typeof lst !== "undefined") {
getField("CityOfService").setItems(lst);
} else {
getField("CityOfService").clearItems();
}
}
}


julie12
Registered: Oct 25 2010
Posts: 4
Thanks - even when I restarted, it didn't work. However, I created a new form, made the combo boxes first and then entered the code and it worked! (There were a lot of modifications to the properties to the combo boxes on my previous form). Interesting that that mattered.

Thanks for your help, much appreciated.