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

Updating multiple drop down list fields based on selection from single drop down list field

Community Beginner ,
Aug 22, 2023 Aug 22, 2023

I'm using Acrobat Pro DC 2020 and am having trouble working with dependent drop-down fields.  I have a drop-down field called "Department" and have several departments to choose from in that list.  I then have 13 different drop-down fields called "Account1, Account2, etc."  When choosing Department A on the first drop-down list, I'd like the 13 dependent drop-downs to have a specific list of choices.  If I choose Department B on the first drop-down list, I'd like the 13 dependent drop-downs to have a different specific list of choices.

 

I have working code that causes the drop-down list for Account1 to change based on the selection from the Department drop-down list.  I can't figure out how to make the selection from the Department drop-down list affect Account1, Account2... all the way to Account13.

 

Here is what I have now (that isn't working). The code is placed on the Format tab - Custom Format Script in the Properties of the Department field:

if(event.value == "Technology")
{
this.getField("Account1").setItems(["--","Computers","Printers","Scanners"]);
this.getField("Account2").setItems(["--","Computers","Printers","Scanners"]);
}
else if(event.value == "Marketing")
{
this.getField("Account1").setItems(["--","Mail","Television","Posters"]);
this.getfield("Account2").setItems(["--","Mail","Television","Posters"]);
}
else
{
this.getField("Account1").clearItems();
this.getField("Account2").clearItems();
}

 

I'm hoping that someone can tell me what I'm missing.  Thanks for any help you can provide.

TOPICS
JavaScript , PDF forms
2.6K
Translate
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Aug 22, 2023 Aug 22, 2023

You also have error in your script, for 'Marketing' in field "Account2" change:

this.getfield

to:

this.getField

View solution in original post

Translate
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 ,
Sep 08, 2023 Sep 08, 2023

When you open the form it kicks the format script.

Use the script at validation. 

View solution in original post

Translate
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 ,
Aug 22, 2023 Aug 22, 2023

Put the script at the Validate tab.

Translate
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 ,
Aug 22, 2023 Aug 22, 2023

Nesa's answer fixed the issue I was having, but I'm curious to know what the difference is between putting the script where I have it and the Validate tab.  I don't understand what makes that different.

Translate
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 ,
Aug 22, 2023 Aug 22, 2023

You also have error in your script, for 'Marketing' in field "Account2" change:

this.getfield

to:

this.getField

Translate
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 ,
Aug 22, 2023 Aug 22, 2023

That's all it was.  I didn't know that caps really mattered, so I would never have caught that.  Thank you.  So simple.

Translate
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 ,
Aug 22, 2023 Aug 22, 2023

If you want to apply the same values to all fields you can use something like this:

 

var newValues = ["--","Computers","Printers","Scanners"];
for (var i=1; i<=13; i++) this.getField("Account"+i).setItems(newValues);

 

[Edited: Code fixed]

Translate
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 ,
Aug 22, 2023 Aug 22, 2023

Where would you apply that script?  It seems like it would save a ton of space in the script to make it less complicated.

Translate
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 ,
Aug 22, 2023 Aug 22, 2023

Instead of these lines:

this.getField("Account1").setItems(["--","Computers","Printers","Scanners"]);
this.getField("Account2").setItems(["--","Computers","Printers","Scanners"]);

Going up to Account13.

Translate
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 ,
Aug 23, 2023 Aug 23, 2023

That worked perfectly.  Thank you both for your help.  This will be much better than what I was trying.

Translate
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 ,
Aug 22, 2023 Aug 22, 2023

Missing + sign: ("Account"i)

Translate
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 ,
Aug 23, 2023 Aug 23, 2023

True. Thanks for the correction, Nesa!

Translate
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 ,
Sep 08, 2023 Sep 08, 2023

I'm hoping that you can provide a little more assistance with this one.  Using the code suggested by try67 works and does exactly what I was hoping for.  However, one strange thing happens.  I choose the Department I want and can then choose the specific accounts for that Department.  If I save the form, close it, and re-open it, the Account fields all go back to showing --.  The Department is still what I set it to, but it changes the Accounts I chose back to nothing.  Is there a way to actually save that information when you save the form?  In most cases the user will want o use the same Department and likely the same Accounts each time they use it.  Does that make sense?

Translate
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 ,
Sep 08, 2023 Sep 08, 2023

Where does you use the script? 

Translate
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 ,
Sep 08, 2023 Sep 08, 2023

It's on the Format tab of the Department field.

Translate
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 ,
Sep 08, 2023 Sep 08, 2023

The method setItems resets the list to the first entry. 

Translate
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 ,
Sep 08, 2023 Sep 08, 2023

You're saying that there's no getting around that then?  Because setItems is in the script, it will always reset to the first value when opening the form?

Translate
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 ,
Sep 08, 2023 Sep 08, 2023

When you open the form it kicks the format script.

Use the script at validation. 

Translate
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 ,
Sep 11, 2023 Sep 11, 2023

That's working!  Thanks very much for your help.

Translate
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 ,
Sep 17, 2023 Sep 17, 2023

Hello, I am attempting to do something similar to @ryanc87715291 in Acrobat Pro 23.006.20320 , but populating 3 or more fields, instead of just two.  I am using the following script in the Validation tab of a drop-down field, which contains time zones and specific location options:

 

if(event.value == "EST")
{
this.getField("Pharmacy Fax Number").setItems(["8443314179"]);
this.getField("M-F Hours of Operation").setItems(["9:00 am - 11:00 pm"]);
this.getField("Sat-Sun Hours of Operation").setItems(["9:00 am - 9:00 pm"]);
}
else if(event.value == "CST")
{
this.getField("Pharmacy Fax Number").setItems(["8445753361"]);
this.getField("M-F Hours of Operation").setItems(["8:00 am - 10:00 pm"]);
this.getField("Sat-Sun Hours of Operation").setItems(["8:00 am - 8:00 pm"]);
}
else if(event.value == "Lubbock")
{
this.getField("Pharmacy Fax Number").setItems(["8446020229"]);
this.getField("M-F Hours of Operation").setItems(["8:00 am - 10:00 pm"]);
this.getField("Sat-Sun Hours of Operation").setItems(["8:00 am - 8:00 pm"]);
}
else if(event.value == "Houston")
{
this.getField("Pharmacy Fax Number").setItems(["8669361865"]);
this.getField("M-F Hours of Operation").setItems(["8:00 am - 10:00 pm"]);
this.getField("Sat-Sun Hours of Operation").setItems(["8:00 am - 8:00 pm"]);
}
else if(event.value == "San Antonio")
{
this.getField("Pharmacy Fax Number").setItems(["8669361864"]);
this.getField("M-F Hours of Operation").setItems(["8:00 am - 10:00 pm"]);
this.getField("Sat-Sun Hours of Operation").setItems(["8:00 am - 8:00 pm"]);
}
else if(event.value == "MST")
{
this.getField("Pharmacy Fax Number").setItems(["8443314159"]);
this.getField("M-F Hours of Operation").setItems(["7:00 am - 9:00 pm"]);
this.getField("Sat-Sun Hours of Operation").setItems(["7:00 am - 7:00 pm"]);
}
else if(event.value == "PST")
{
this.getField("Pharmacy Fax Number").setItems(["8558792669"]);
this.getField("M-F Hours of Operation").setItems(["6:00 am - 8:00 pm"]);
this.getField("Sat-Sun Hours of Operation").setItems(["6:00 am - 6:00 pm"]);
}
else
{
this.getField("Pharmacy Fax Number").clearItems();
this.getField("M-F Hours of Operation").clearItems();
this.getField("Sat-Sun Hours of Operation").clearItems();

---------------------------------------------------------------------------

 

The first field in the script for each location/time zone (Pharmacy Fax) populates fine in that field (a drop down field, formatted for phone number, with the fax numbers included), but I can't get the other 2 fields to populate (M-F Hours of Operation and Sat-Sun Hours of Operation) for any of the locations/time zones. Those 2 are basic text fields, with no formatting. Do I need to make those 2 fields drop-downs with the options included to get this to work? 

Am I doing something else wrong?

 

Thanks for any assistance!

Translate
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 ,
Sep 17, 2023 Sep 17, 2023

Actually, all 3 fields should be text fields, just instead of 'setItems()' use 'value', like this:

if(event.value == "EST"){
this.getField("Pharmacy Fax Number").value = "8443314179";
this.getField("M-F Hours of Operation").value = "9:00 am - 11:00 pm";
this.getField("Sat-Sun Hours of Operation").value = "9:00 am - 9:00 pm";}
Translate
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 ,
Sep 18, 2023 Sep 18, 2023
LATEST

@Nesa Nurani, that worked!!  Thank you so much!

Translate
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