Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You also have error in your script, for 'Marketing' in field "Account2" change:
this.getfield
to:
this.getField
Copy link to clipboard
Copied
When you open the form it kicks the format script.
Use the script at validation.
Copy link to clipboard
Copied
Put the script at the Validate tab.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You also have error in your script, for 'Marketing' in field "Account2" change:
this.getfield
to:
this.getField
Copy link to clipboard
Copied
That's all it was. I didn't know that caps really mattered, so I would never have caught that. Thank you. So simple.
Copy link to clipboard
Copied
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]
Copy link to clipboard
Copied
Where would you apply that script? It seems like it would save a ton of space in the script to make it less complicated.
Copy link to clipboard
Copied
Instead of these lines:
this.getField("Account1").setItems(["--","Computers","Printers","Scanners"]);
this.getField("Account2").setItems(["--","Computers","Printers","Scanners"]);
Going up to Account13.
Copy link to clipboard
Copied
That worked perfectly. Thank you both for your help. This will be much better than what I was trying.
Copy link to clipboard
Copied
Missing + sign: ("Account"i)
Copy link to clipboard
Copied
True. Thanks for the correction, Nesa!
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Where does you use the script?
Copy link to clipboard
Copied
It's on the Format tab of the Department field.
Copy link to clipboard
Copied
The method setItems resets the list to the first entry.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
When you open the form it kicks the format script.
Use the script at validation.
Copy link to clipboard
Copied
That's working! Thanks very much for your help.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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";}
Copy link to clipboard
Copied
@Nesa Nurani, that worked!! Thank you so much!