Skip to main content
ryanc87715291
Participating Frequently
August 22, 2023
Answered

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

  • August 22, 2023
  • 4 replies
  • 3558 views

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.

Correct answer Bernd Alheit

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?


When you open the form it kicks the format script.

Use the script at validation. 

4 replies

Participant
September 18, 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!

Nesa Nurani
Community Expert
Community Expert
September 18, 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";}
Participant
September 18, 2023

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

try67
Community Expert
Community Expert
August 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]

ryanc87715291
Participating Frequently
August 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.

try67
Community Expert
Community Expert
August 22, 2023

Instead of these lines:

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

Going up to Account13.

Nesa Nurani
Community Expert
Community Expert
August 22, 2023

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

this.getfield

to:

this.getField

ryanc87715291
Participating Frequently
August 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.

Bernd Alheit
Community Expert
Community Expert
August 22, 2023

Put the script at the Validate tab.

ryanc87715291
Participating Frequently
August 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.