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

Two or more dependent lists by one main list

Community Beginner ,
Jun 08, 2019 Jun 08, 2019

Copy link to clipboard

Copied

Hi, this is my problem. In my pdf document, I want a main dropdown list "mainList" and a dependent dropdown list "depList1". When I choose the value in "mainList", the values in "depList1" change. In "mainList" I use this script, with three values "0", "1" and "2" that show different choices in "depList1", with the relative values:

var dependentListBoxFieldName = "depList2";

var dependentListValues =

{

"0": [

[" ", "0"]

],

"1": [

[" ", "0"]

["white", "1"],

["green", "2"],

["red", "3"],

],

"2": [

[" ", "0"]

["white", "1"],

["blue", "2"],

["yellow", "3"],

};

if ((event.target.type == "combobox" && event.name == "Format") || (event.target.type == "listbox" && event.name == "Keystroke")) {

if (event.target.type == "combobox") {

if (dependentListValues.hasOwnProperty(event.target.value)) {

this.getField(dependentListBoxFieldName).setItems(dependentListValues[event.target.value]);

}

else {

this.getField(dependentListBoxFieldName).clearItems();

}

}

if (event.target.type == "listbox" && dependentListValues.hasOwnProperty(event.changeEx)) {

this.getField(dependentListBoxFieldName).setItems(dependentListValues[event.changeEx]);

}

}

else {

app.alert("This script was not intended for this field type or event.");

So, I want a second dropdown list "depList2" that changes its values together "depList1", when I change the choose in "mainList". In other words, I want two or more dependent dropdown lists all dependent by only one main list. Can I use the same script? Can I use another script? Thank you so much

TOPICS
Acrobat SDK and JavaScript , Windows

Views

579

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 1 Correct answer

Community Beginner , Jun 08, 2019 Jun 08, 2019

Ok, now it works. I renamed the vars with numbers (1,2,3..). but I also repeat all the final string with the new names of vars, one string for every dependent list. Maybe it's a overflowing script but it works. This is the final script:

var dependentListBoxFieldName1 = "depList1";

var dependentListValues1 =

{

"1": [

["Choice 1.1", "1"],

],

"2": [

["Choice 1.2", "2"],

]

};

var dependentListBoxFieldName2 = "depList2";

var dependentListValues2 =

{

"1": [

["Choice 2.1", "1"],

],

"2": [

["Choice 2.2", "2"],

]

};

if ((e

...

Votes

Translate

Translate
Community Expert ,
Jun 08, 2019 Jun 08, 2019

Copy link to clipboard

Copied

You can use

dependentListBoxFieldName1

dependentListValues1

dependentListBoxFieldName2

dependentListValues2

dependentListBoxFieldName3

dependentListValues3

and so on

Copy the code and adjust the code.

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 Beginner ,
Jun 08, 2019 Jun 08, 2019

Copy link to clipboard

Copied

I also thought that this is the simplest solution but it doesn't work, I don't know why

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 ,
Jun 08, 2019 Jun 08, 2019

Copy link to clipboard

Copied

Where is this script called? 

These lines are completely unnecessary because you already know the event where the script is called and the type of field where it is used.

if ((event.target.type == "combobox" && event.name == "Format") || (event.target.type == "listbox" && event.name == "Keystroke")) {

if (event.target.type == "combobox") {

if (dependentListValues.hasOwnProperty(event.target.value)) {

If this script is used in a format event, or keystroke, then the correct value of the field is "event.value" not "event.target.value"

Read this article. It provides the information you need.

https://acrobatusers.com/tutorials/js_list_combo_livecycle

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Jun 08, 2019 Jun 08, 2019

Copy link to clipboard

Copied

The code comes from here:

Dependent 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 Beginner ,
Jun 08, 2019 Jun 08, 2019

Copy link to clipboard

Copied

This string is apparently useless but without it the script does not work

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 Beginner ,
Jun 08, 2019 Jun 08, 2019

Copy link to clipboard

Copied

LATEST

Ok, now it works. I renamed the vars with numbers (1,2,3..). but I also repeat all the final string with the new names of vars, one string for every dependent list. Maybe it's a overflowing script but it works. This is the final script:

var dependentListBoxFieldName1 = "depList1";

var dependentListValues1 =

{

"1": [

["Choice 1.1", "1"],

],

"2": [

["Choice 1.2", "2"],

]

};

var dependentListBoxFieldName2 = "depList2";

var dependentListValues2 =

{

"1": [

["Choice 2.1", "1"],

],

"2": [

["Choice 2.2", "2"],

]

};

if ((event.target.type == "combobox" && event.name == "Format") || (event.target.type == "listbox" && event.name == "Keystroke")) {

if (event.target.type == "combobox") {

if (dependentListValues1.hasOwnProperty(event.target.value)) {

this.getField(dependentListBoxFieldName1).setItems(dependentListValues1[event.target.value]);

}

else {

this.getField(dependentListBoxFieldName1).clearItems();

}

}

if (event.target.type == "listbox" && dependentListValues1.hasOwnProperty(event.changeEx)) {

this.getField(dependentListBoxFieldName1).setItems(dependentListValues1[event.changeEx]);

}

}

else {

app.alert("This script was not intended for this field type or event.");

}

if ((event.target.type == "combobox" && event.name == "Format") || (event.target.type == "listbox" && event.name == "Keystroke")) {

if (event.target.type == "combobox") {

if (dependentListValues2.hasOwnProperty(event.target.value)) {

this.getField(dependentListBoxFieldName2).setItems(dependentListValues2[event.target.value]);

}

else {

this.getField(dependentListBoxFieldName2).clearItems();

}

}

if (event.target.type == "listbox" && dependentListValues2.hasOwnProperty(event.changeEx)) {

this.getField(dependentListBoxFieldName2).setItems(dependentListValues2[event.changeEx]);

}

}

else {

app.alert("This script was not intended for this field type or event.");

}

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