Copy link to clipboard
Copied
Hi,
I am new to using adobe and I am trying to make two drop down boxes work together. What I need is for the selected item in either drop down to populate the other drop down with the corresponding selection and vice versa. I have been able to make the two separate drop down boxes and put all list items in their respective boxes, but I have no idea how to make the two correspond with eachother. Any help would be much appreciated.
Thanks!
Running Acrobat Pro DC
Copy link to clipboard
Copied
In order to do what you are asking requires a method for mapping the entries in one list to the entries in the other list. The script that does this could be a format, validate, or keystroke script. This part really isn't imporant. The important bit is to have method for mapping the entries between the lists.
There are several ways this can be done. One method is to hard code the mapping in the script itself, as suggested by Nesa. However, I prefer to go with a more generic approach. Make the data embody the mapping. For example, in the first list, the main entry text is the part number and the export value is the description. Then in the second list the main entry text is the descripting and the export value is the part number. Now all the script needs to do is set the other field to the display (main) value of current field. The scripts on both dropdowns are identical, only the data is different.
Another approach is to use a generic object to contain the lists and map the values.
Like this: var oList = {"1155AB":"The small part", "2255CD":"The Large Part"};
Then the script sets the other dropdown according values in the object. The advantage of this approach is that this object can also be used to populate the dropdowns, so you have a automated path to updating the part list that stems from a single source, i.e., the list object. This method can be easily combined with the first one I described.
Copy link to clipboard
Copied
Thom,
Most of this is a little over my head but I'm willing to try. I really like the way you said to use a generic object to contain the lists, but I have no idea how to execute any of that.
Copy link to clipboard
Copied
There are 3 parts to using the method I described. And it takes some scripting chops.
1) Create the Parts list in a document script.
var oList = {"1155AB":"The small part", "2255CD":"The Large Part"};
2) Create a function for populating the fields, also at document level. Since you have several dropdowns. I would suggest using group naming
So "PartNum.Row1", "PartNum.Row2", etc. "PartDesc.Row1", "PartDesc.Row2", etc.
This makes it much easier to create loops for setting lists to the fields.
Do not call this function in the document script, just define it. You'll only need to call it when the lists need to be loaded. So do this part manually from the console window.
I'd set this up so that the export value for both lists is the part number.
3) Use a Keystroke script to set the value in the other field.
Like this
if(!event.willCommit)
{// Get field name for other field first.
cListName = "PartDesc." + event.targetName.split(".").pop();
this.getField(cListName).value = event.changeEx;
}
Notice how the field name for the other list field on the same row is built from part of the name from the current field. This assumes the field naming I proposed.
Copy link to clipboard
Copied
The keystroke script (in part 3) above will provide exactly the functionality you want.
However, it depends on the export value of the entries in the lists being the same for both fields.
To do this, do not fill out the "export" value for the part number list. The export value defaults to the display value, if its not specified. But for the description list, use the part number as the export value.
This will solve your first issue. But you have others. There are several lines of these fields on the form. You need a methodology that will allow you to quickly update the lists if something changes. You also need to be able to easily add the scripts to all of those fields.
Copy link to clipboard
Copied
Thom,
I was able to make the var oList in part one, but I'm pretty clueless on how to do part 2. Example? Help?
Copy link to clipboard
Copied
The items in a List (dropdown) field are set with the "field.setItems()" function. Here's the reference entry.
The input to this function is an array of list field entries, so the trick is to get all the values in the Part List Object (Part 1) into an array.
You can find out all about programming Acrobat list fields here:
https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm
Say that the field are named as I suggested in Part 2, i.e., "PartNum.Row1", "PartNum.Row2", etc. "PartDesc.Row1", "PartDesc.Row2", etc.
This function will set the values in a specific row.
function SetPartListInRow(cRowName)
{
var aPartNumList=[], aPartDescList=[];
for(var nm in oList)
{
aPartNumList.push(nm);
aPartDescList.push([oList[nm],nm]);
}
this.getField("PartNum." + cRowName).setItems(aPartNumList);
this.getField("PartDesc." + cRowName).setItems(aPartDescList);
}
To use this function, Open the console window and run this code
SetPartsListInRow("Row1");
Now the list fields in the first row will be setup with the correct list values. When you need to make an update, change the list in the document script and then rerun this function. Much faster, easier, and more reliable, than manually updates the lists.
You could improve this function by added code for looping over all the rows and by automatically adding the custom keystroke scripts. So you never have to edit the actual fields. It's all done automatically from this setup function.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now