Skip to main content
washingtontrust
Participating Frequently
May 25, 2018
Answered

Auto populate a drop down menu from text field entries?

  • May 25, 2018
  • 5 replies
  • 2079 views

I have been searching the forums for hours but cannot find a solution for this, which seems like it would be more simple than much of the questions I have been looking at. I do not have much experience with running scripts in Acrobat, but I am willing to learn. I have seen many forum answers referring to "LiveCycle", but I don't think I have that. I am running Adobe Acrobat CC and all is up to date.

I want to create a fillable PDF where there is a dropdown menu that populates its options with the text from text fields earlier in the document that the user fills out. Is this possible?

This topic has been closed for replies.
Correct answer try67

I would do it using a (hidden) text field with the following calculation script:

var textFields = ["Text1", "Text2", "Text3", "Text4", "Text5"];

if (event.source!=null && textFields.indexOf(event.source.name)!=-1) {

    var items = [];

    for (var i in textFields) {

        items.push(this.getField(textFields).valueAsString;

    }

    this.getField("Dropdown1").setItems(items);

}

The field names in the array and in line # need to be adjusted, of course.

5 replies

Participant
November 7, 2018

I do appreciate your help. Thank you very much try67

Participant
November 7, 2018

Amazingly working thank you!

I have anothe question if you don't mind

I want to auto populate another text field from the selected answer in the dropdown menu I have just created

try67
Community Expert
Community Expert
November 7, 2018

So you want to copy the value selected in the drop-down to a text field? If so, use this code as the custom calculation script of the text field:

event.value = this.getField("Dropdown 5").valueAsString;

Use the actual field name in your file, of course.

Participant
November 7, 2018

Thank you for your interest try67 Here is the code:

var textFields = ["Original story", "Me story", "Opposite story", "Desired story"];    if (event.source!=null && textFields.indexOf(event.source.name)!=-1) {      var items = [];      for (var i in textFields) {          items.push(this.getField(textFields).valueAsString;      }      this.getField("Dropdown1").setItems(items);  }

try67
Community Expert
Community Expert
November 7, 2018

As the error message says, you're missing a closing parenthesis, namely in this line:

items.push(this.getField(textFields).valueAsString;

It should be:

items.push(this.getField(textFields).valueAsString);

Participant
November 7, 2018

Hello,

Thank you for your help. I am newbie to this coding...
I have the same desire ; creating a dropdown list auto populated from text fields. I have done these steps:

1- I created an invisible text field

2- "Copy and paste" the above script under properties/calculation of the invisible text field

3- changes "text1", " text2" .... to their appropriate names.

then I got this error

So, my question is: are the steps correct/enough to make it done? How to fix the error

Thank you for your care!

try67
Community Expert
Community Expert
November 7, 2018

Post your full code as text, please.

try67
Community Expert
Community Expert
May 25, 2018

Yes, but it's tricky. You need to define when the drop-down list should be updated. Is it each time one of the text fields is changed? What if the user already made a selection in it? etc.

washingtontrust
Participating Frequently
May 25, 2018

Ideally it would update each time the text fields are changed.

For specifics, it is an application where I am asking users to describe a project and later create a timeline for it. So, I have users breaking their projects into up to five over arching "work elements", and then later breaking out a timeline to describe the smaller steps for the projects. Because steps from each work element will likely happen concurrently, I was hoping to allow users to enter a step in the timeline and then select the work element it was related to. That way, the timeline can be chronological and show overlapping work between "work elements".

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 25, 2018

I would do it using a (hidden) text field with the following calculation script:

var textFields = ["Text1", "Text2", "Text3", "Text4", "Text5"];

if (event.source!=null && textFields.indexOf(event.source.name)!=-1) {

    var items = [];

    for (var i in textFields) {

        items.push(this.getField(textFields).valueAsString;

    }

    this.getField("Dropdown1").setItems(items);

}

The field names in the array and in line # need to be adjusted, of course.