• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Cascading List box (Not Drop down list box) issue

New Here ,
Nov 26, 2020 Nov 26, 2020

Copy link to clipboard

Copied

I am new to PDF forms.


I created three list boxes. Master List box, Frist Dependent List box, Second Dep List box.

Master List box  >> First Dependent List box  >>  Second Dep List box.


I am trying to populate First Dependent List box based on selected item in Master List box. And trying to populate Second Dep List box based on item selected in First Dependent List box.

When I select Master List box item, the First Dependent List box items changes accordingly.
However I am unable to list any items in Second Dep List box and also unable to view any items in Second Dep List box when I select any item in First Dependent List box.

 

I want :
When Master List box item is selects, the First Dependent List box item should change. And when I select First Dependent List box item, the Second Dep List box item should appear/change.

 

Master List Box >> First Dependent List Box >> Second Dep List Box
Example: Europe >> France >> Paris

 

Can anybody please help me with the code for three or more List boxes code.

I found multiple examples of Cascading drop down list box and I tried to modify them for Cascaded List box however Drop down List box code does not work for Regular List box.

TOPICS
Acrobat SDK and JavaScript

Views

894

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Nov 26, 2020 Nov 26, 2020

See if something like this works for you:
Put code in Master List Box:
var list1 = this.getField("First Dependent List Box");

if (event.value == "Europe") {
list1.clearItems();
list1.insertItemAt("France");
list1.insertItemAt("England");
} else if ( event.value == "USA"){
list1.clearItems();
list1.insertItemAt("Texas");
list1.insertItemAt("Utah");
}else list1.clearItems();

 

Put code in First Dependent List Box:
var list2 = this.getField("Second Dep List Box");

if (event.value == "France") {
list2.clearItems();

...

Votes

Translate

Translate
Community Expert , Nov 26, 2020 Nov 26, 2020

I writed in my post to put code in list box, code is for "selection change". 

I think OP wants a list box and not a dropdown to act as cascade (select item in master list-then select in first dependent list and then in second dependent list) 

Votes

Translate

Translate
Community Expert ,
Nov 26, 2020 Nov 26, 2020

Copy link to clipboard

Copied

You need to share your code.

 

Is hard to tell what is wrong without taking a look at it.

 

Also, you keep referring to cascading dropdown lists.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2020 Nov 26, 2020

Copy link to clipboard

Copied

See if something like this works for you:
Put code in Master List Box:
var list1 = this.getField("First Dependent List Box");

if (event.value == "Europe") {
list1.clearItems();
list1.insertItemAt("France");
list1.insertItemAt("England");
} else if ( event.value == "USA"){
list1.clearItems();
list1.insertItemAt("Texas");
list1.insertItemAt("Utah");
}else list1.clearItems();

 

Put code in First Dependent List Box:
var list2 = this.getField("Second Dep List Box");

if (event.value == "France") {
list2.clearItems();
list2.insertItemAt("Paris");
list2.insertItemAt("Lyon");
} else if (event.value == "England"){
list2.clearItems();
list2.insertItemAt("London");
list2.insertItemAt("Liverpool");
} else if (event.value == "Utah"){
list2.clearItems();
list2.insertItemAt("Salt Lake City");
list2.insertItemAt("San Juan");
} else if (event.value == "Texas"){
list2.clearItems();
list2.insertItemAt("Dallas");
list2.insertItemAt("Houston");
}else list2.clearItems();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2020 Nov 26, 2020

Copy link to clipboard

Copied

Nesa can yuo explain where to run this code? 

 

The OP has repeatedly referred to Cascading Dropdown Listbox and Regular Listbox creating confusion with these terms.

 

Listbox and combobox (or dropdown menu) are two different things. And yes the OP is right when observing that the code varies slightly if it will be  run from a Listbox not a combobox.

 

If it is a listbox, is that script used as a Mouse-up event or is it used as "Selection Change" script?

 

If it is a dropdown menu is it a custom format script  or a custom keystroke? Or is it a combination of both format and keystroke scripts?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2020 Nov 26, 2020

Copy link to clipboard

Copied

I writed in my post to put code in list box, code is for "selection change". 

I think OP wants a list box and not a dropdown to act as cascade (select item in master list-then select in first dependent list and then in second dependent list) 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 26, 2020 Nov 26, 2020

Copy link to clipboard

Copied

Got it. I missed that part.

 

Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 27, 2020 Nov 27, 2020

Copy link to clipboard

Copied

LATEST

Thanks Nesa,

Thank you very much.

Your code worked perfectly. Appreciate your help.

I used it and changed it to some extent as each listbox have 80+ list items so for: 
Continent >> Country >> State >> Capital >> Pin Code

I added below script in MasterListBox and similar script further in each DependentListBoxX.

 

var dependentListBoxFieldName = "dependentListBox1";
var dependentListValues =
{
"Oceania": [
["Australia", "australia"],
["New Zealand", "new zealand"],
["Fiji", "fiji"]
],
"North America": [
["USA", "usa"],
["Canada", "canada"],
["Caribbean", "caribbean"]
],
"Europe": [
["Germany", "germany"],
["France", "france"],
["UK", "uk"]
],
"Asia": [
["India", "india"],
["China", "china"],
["Rusia", "russia"]
]
};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines