Copy link to clipboard
Copied
Hi, I was wondering if there is a way to auto populate 4 different text fields with 4 different values, when you select a certain item from a drop down?
Copy link to clipboard
Copied
Hi,
Yes you can, you must employ a JavaScript script.
Copy link to clipboard
Copied
Read these articles:
https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm
https://acrobatusers.com/tutorials/change_another_field/
This question is asked almost daily. Do a little searching on the forums.
Copy link to clipboard
Copied
Hi there, I'm hoping someone can help me please, I've been scouring the forums and Internet and can't seem to find an answer to my particular problem.
Like the original poster above I am looking to autopopulate 4 fields after a dropdown box selection. In my case it is the 2nd dropdown box of 2, where the 1st dropdown box determines the choices in the 2nd.
Using the 2 articles above,
https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm
https://acrobatusers.com/tutorials/change_another_field/
I have managed, through a lot of trial and error, to figure out how to get this working.
My issue/problem lies with me wanting to have multiple rows of the same 2 dropdown boxes and 4 autopopulated field boxes. Whenever I try to set that up the best I can come up with is that both dropdown boxes work correctly but the text fields all give the same data (the data for the first row), on each of the subsequent rows even if the dropdown choices are different. I can't seem to figure how to get them working independantly.
For clarification: Dropbox 1 is a choice of magic school, Dropbox 2 is a choice of spell from the previously chosen school in Dropbox 1. The 4 field boxes represent the 'Casting Time', 'Duration', 'Type' and 'Ingredient' of the spell chosen in Dropbox 2.
I can get one line of this working correctly, where all 4 text boxes correctly display the information of the chosen spell but cannot figure out how to get each subsequent spell chosen in the next row to display the information independantly.
Any help at all would be gratefully received as I'm trying to set up a form fillable character sheet for a typing impaired person.
Jim
Copy link to clipboard
Copied
Give fields unique name, for example:
1st row:
Dropbox1.row1, Dropbox2.row1, Casting Time.row1, Duration.row1, Type.row1, Ingredient.row1
2nd row:
Dropbox1.row2, Dropbox2.row2, Casting Time.row2, Duration.row2, Type.row2, Ingredient.row2
...etc
Copy link to clipboard
Copied
The "Change Another Field" article uses a document level fuction (SetFieldValues()) to set the field values from a dropdown selection. In that function the target field names are hard coded. That method works for a single field set, but needs modification to extend to multiple parallel field sets. And for that you need a bit of abstraction.
Nesa provides the perfect solution for the abstraction, which is to use a field naming pattern for the parallel field sets. Then the modification to the original method is to build the target field names from the name of the current field. (the current field being the field that is running the script). This works because the current field shares the same naming pattern as the other fields in it's field set.
So if the current field is "Dropdown2.row1", then it is the "row1" bit that distinguishes the field set. The "SetFieldValues() function can then be modified to dynamically build the target field names like this:
function SetFieldValues(cSelectValue) {
// Get Row name for field set from the name of the current field
var strRow = event.targetName.split(".").pop();
// Populate fields with values from the Dataset
this.getField("Casting Time." + strRow).value = Dataset[cSelectValue].CastingTime;
this.getField("Duration." + strRow).value = Dataset[cSelectValue].Duration;
this.getField("Type." + strRow).value = Dataset[cSelectValue].Type;
}
Now the function will work with any field set.
I don't know what your version of this function or the dataset look like, so you'll need to modify this code for your particular situation.
Copy link to clipboard
Copied
Just wanted to say thank you Nesa and Thom for your help. Between the advice you both gave, and a lot of trial and error, I managed to get the code to do what I wanted it to do. 🙂
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more