• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Auto populate a drop down menu from text field entries?

Community Beginner ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

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?

TOPICS
Acrobat SDK and JavaScript

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 25, 2018 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.

Votes

Translate

Translate
Community Expert ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

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".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

I'm not sure what you mean by hidden text field? Would they need to be separate from the text fields in which the users are giving their inputs?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

Yes, it will only be used to trigger the calculation script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

I would actually be okay with the dropdown resetting if the text fields are changed. I would prefer as simple a script as possible as this is all new to me. I have only ever run numerical calculations with scripts before.

So, I create a hidden text field that has this calculation script listed in it? Or does the calculation go into the Dropbox "calculation" script area?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

It worked! Thanks so much!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

To clarify, if the user has already made a selection from the dropdown and the text changes, I would prefer that their selection reflects that change and just auto updates with the new text. The main goal would be to have the dropdown menus (there will be multiple of them) always refer to the same five text boxes, no matter what their inputs are.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

That will require a much more complex script. The code above will reset their selection when the text fields are changed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

I would actually change line #4 in the code above from:

var items = [];

To something like:

var items = [""];

So there's a blank value selected by default, instead of an actual one.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 07, 2018 Nov 07, 2018

Copy link to clipboard

Copied

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

Capture.PNG

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

Thank you for your care!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2018 Nov 07, 2018

Copy link to clipboard

Copied

Post your full code as text, please.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 07, 2018 Nov 07, 2018

Copy link to clipboard

Copied

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);  }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2018 Nov 07, 2018

Copy link to clipboard

Copied

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 07, 2018 Nov 07, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2018 Nov 07, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 07, 2018 Nov 07, 2018

Copy link to clipboard

Copied

LATEST

I do appreciate your help. Thank you very much try67

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines