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
  • 3601 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
September 8, 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?

Bernd Alheit
Community Expert
Community Expert
September 8, 2023

Where does you use the script? 

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.