PDF dropdown entries depend on another field in the document
Copy link to clipboard
Copied
Hi,
I would like to create a drop down list where the drop down options should be taken from another field in the pdf form. To explain it a bit more...
I have created a form list with "name1" another field with "name2"... and so on. These fields occur in various places in my form. I would now like to have a drop down list that displays the actual name and enters the actual name when using it. So if "name1" is "Eddie", I would like to be able to select "Eddie" from my drop down list. Is this possible? And if so how?
I am not very advanced with pdf forms and just trying to put some things together for my class.
Thanks in advance.
Copy link to clipboard
Copied
You could gather all those names in array and use setItems() to set those names in dropdown field.
Copy link to clipboard
Copied
I don't want to set these names. I would like them to be variable so that next year I can just change name1 etc and still use the same form. But thank you for the idea.
Copy link to clipboard
Copied
Setting the values means applying them to the drop-down field so they can be selected. It does not mean they can't be changed later on.
You need to better explain how it should work, though. What items should field 2 have if "Eddie" is selected in field 1? Just "Eddie"? For that you don't need a drop-down. Just use a text field and copy the selected value from field 1 into it.
Copy link to clipboard
Copied
It is for a school. So I have a name list from "Name1", "Name2"...fields. I can type the name of the child in there and Name1 is then always the child1 name in various places in my form.
Now I would like to create a seating plan for each week. So I have created a dropdown list with all the names of the children to choose from. This works well but it isn't handy, when the group of children (Name1, Name2) change. Therefore, I would really like to use "Name1" and "Name2" for the dropdown list so that when the group of children changes the seating plan drop downs also change. Does that make sense?
Copy link to clipboard
Copied
Yes, that makes more sense. But now the question is when should these lists be updated? If you update them each time you change the name in one of the text fields it will overwrite all of the values you already selected in the seating plan, and you'll have to re-do your work.
I would recommend using a button (it can be transparent) to update the lists.
To do so you can use something like this code (let's say there are 10 Name fields and 10 Seat fields):
var names = [""];
for (var i=1; i<=10; i++) {
var name = this.getField("Name"+i).valueAsString;
if (names.indexOf(name)==-1) names.push(name);
}
for (var i=1; i<=10; i++) {
this.getField("Seat"+i).setItems(names);
}
When you click the button all the names will be collected and applied to the Seat fields as their new options, reverting them to the default blank option as the selected one.
Copy link to clipboard
Copied
This is one idea but the "Name1", "Name2".... list only changes every school year, where as the seating plan changes every week, as they choose new seats every week. I have duplicated the seating plan. So on seating plan 1 currently the dropdown fields are called seat122, seat 222, seat 322.... This is because we are in week 22. Next week the seating plan will have the seats called seat123, seat223, seat323.... I would like to store the seating plans that is why I duplicated the page and changed the names of the seats.
I am sure there is an easier way as adjusting the seat names takes a bit of time but for now that is the only way I could figure out.
Copy link to clipboard
Copied
That will require a more complex script, but if the names of the seating fields are consistent then it should be possible.
Copy link to clipboard
Copied
Thank you very much for your help. Unfortunatley I can't get it to work. Here is a screenshot of my current set up.
In the bottom corner you can see my drop down. I have this drop down for each seat but I have pre-entered the names of the children in that drop down list. Now I would ideally like those names to be taken from that list. That would save me a lot of hassle, plus my colleagues could use it too.
Copy link to clipboard
Copied
You will need to share the actual file, or at least provide a more detailed description of what you did and what the results were (including any error messages that appear in the JS Console).
Copy link to clipboard
Copied
I have figured out the code for my dropdown list. It is as follows....
var wt0 = this.getField("Name0").value;
var wt1 = this.getField("Name1").value;
var wt2 = this.getField("Name2").value;
var wt3 = this.getField("Name3").value;
var wt4 = this.getField("Name4").value;
var wt5 = this.getField("Name5").value;
var wt6 = this.getField("Name6").value;
var wt7 = this.getField("Name7").value;
var wt8 = this.getField("Name8").value;
var wt9 = this.getField("Name9").value;
var wt10 = this.getField("Name10").value;
var wt11 = this.getField("Name11").value;
var wt12 = this.getField("Name12").value;
var wt13 = this.getField("Name13").value;
var wt14 = this.getField("Name14").value;
var wt15 = this.getField("Name15").value;
var wt16 = this.getField("Name16").value;
var wt17 = this.getField("Name17").value;
var wt18 = this.getField("Name18").value;
var wt19 = this.getField("Name19").value;
var wt20 = this.getField("Name20").value;
var wt21 = this.getField("Name21").value;
var wt22 = this.getField("Name22").value;
var wt23 = this.getField("Name23").value;
var wt24 = this.getField("Name24").value;
var wt25 = this.getField("Name25").value;
var wt26 = this.getField("Name26").value;
var wt27 = this.getField("Name27").value;
var wt28 = this.getField("Name28").value;
var wt29 = this.getField("Name29").value;
var wt30 = this.getField("Name30").value;
this.getField("Sitzplatz 522").setItems([wt0,wt1,wt2,wt3,wt4,wt5,wt6,wt7,wt8,wt9,wt10, wt11,wt12,wt13,wt14,wt15,wt16,wt17,wt18,wt19,wt20,wt21, wt22,wt23,wt24,wt25,wt26,wt27,wt28,wt29,wt30]);
Ideally I would like to put a varible in for "Sitzplatz 522". Instead of 522 I would like to put something like "Sitzplatz §§§"??? The seats are numbered from 122, 222, 322,422 and so on to 3022. First number for the seat, 22 in this case for the week. This is why it isnt 122,123,124 and so on. Is there a way to put something generic in so I don't have to go into each seat and change the "Sitzplatz" number?
Copy link to clipboard
Copied
This is exactly what my code does, only less efficiently.
Copy link to clipboard
Copied
Want you copy the names from one dropdown field to the other dropdown fields?
Copy link to clipboard
Copied
Well I got it to work with this code.
var wt0 = this.getField("Name0").value;
var wt1 = this.getField("Name1").value;
var wt2 = this.getField("Name2").value;
var wt3 = this.getField("Name3").value;
var wt4 = this.getField("Name4").value;
var wt5 = this.getField("Name5").value;
var wt6 = this.getField("Name6").value;
var wt7 = this.getField("Name7").value;
var wt8 = this.getField("Name8").value;
var wt9 = this.getField("Name9").value;
var wt10 = this.getField("Name10").value;
var wt11 = this.getField("Name11").value;
var wt12 = this.getField("Name12").value;
var wt13 = this.getField("Name13").value;
var wt14 = this.getField("Name14").value;
var wt15 = this.getField("Name15").value;
var wt16 = this.getField("Name16").value;
var wt17 = this.getField("Name17").value;
var wt18 = this.getField("Name18").value;
var wt19 = this.getField("Name19").value;
var wt20 = this.getField("Name20").value;
var wt21 = this.getField("Name21").value;
var wt22 = this.getField("Name22").value;
var wt23 = this.getField("Name23").value;
var wt24 = this.getField("Name24").value;
var wt25 = this.getField("Name25").value;
var wt26 = this.getField("Name26").value;
var wt27 = this.getField("Name27").value;
var wt28 = this.getField("Name28").value;
var wt29 = this.getField("Name29").value;
var wt30 = this.getField("Name30").value;
this.getField("Sitzplatz 522").setItems([wt0,wt1,wt2,wt3,wt4,wt5,wt6,wt7,wt8,wt9,wt10, wt11,wt12,wt13,wt14,wt15,wt16,wt17,wt18,wt19,wt20,wt21, wt22,wt23,wt24,wt25,wt26,wt27,wt28,wt29,wt30]);
Now the last issue is that for each seat I have to change "Sitzplatz522" into "Sitzplatz622" etc. Is there a way to put a variable for the numbers? "Sitzplatz§§§" or something like that? The numbers are not all available so it isn't +1 as 22 is the same but the first number changes. So I have seats 122, 222,322,422,522,622,722,822,922,1022,1122....up until 3022. If you could help me solve this issue it would work perfectly. Thank you in advance
Copy link to clipboard
Copied
No I wanted to copy from a form field into a dropdown list but I have solved this problem with the above code. This works for me.

