Create a dynamic dropdown field in Adobe Acrobat Pro XI

Explorer ,
Oct 30, 2014 Oct 30, 2014

Copy link to clipboard

Copied

Hello all. I am trying to create a field in one of my forms using Adobe Acrobat Pro XI. I have a dropdown list of "main" items, and based on what is selected in that list, I want a second dropdown list to give different choices. I have searched and searched and have javascript that I thought might work, but maybe I am have a mistake or I am placing the javascript in the wrong place, becasue it is not working. I know very, very little about javascript, so any help would be so much appreciated.

I am using Adobe Acrobat Pro XI. I added a "new field", and selected "dropdown". The field name is ProvType. The dropdown options are:

     Inpatient

     Outpatient

     Physician

I have the "Commit selected value immediately" selected.The field is not validated. The format is "none." There are no actions or calculations associated with it.

I then created another dropbox, and named it SubProvType. Under Actions, I selected the trigger as Mouse Up, and then selected the Action "Run a JavaScript." I selected the add button, and typed this in the JavaScript editor:

switch (ProvType.rawValue)

{

    case "Inpatient":

        this.setItems("Hospice,Hospital,Nursing Facility");

        break;

    case "Outpatient":

        this.setItems("Adult Day Center,Home,Other");

        break;    

    case "Physician":

        this.setItems("Surgeon,Family Practice,Neurologist");

        break;    

}

What I want to happen is:

If "Inpatient" is selected, I want the following options to be available in the second dropdown box "SubProvType":

     Hospice

     Hospital

     Nursing Facility

If "Outpatient" is selected, I want the following options to be available in the second dropdown box "SubProvType":

     Adult Day Center

     Home

     Other

If "Physician" is selected, I want the following options to be available in the second dropdown box "SubProvType":

     Surgeon

     Family Practice

     Neurologist

However.... when I close the form editing and try to select a different option in the ProvType field, the SubProvType field remains blank and there are no options available. There are also no errors.

I must be missing something, but I have no idea where to start. Thank you in advance for any help anyone can provide.

TOPICS
PDF forms

Views

52.3K

Likes

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

Adobe Community Professional , Oct 30, 2014 Oct 30, 2014
Use this code as the custom validation script of ProvType (and remove any code you associated with SubProvType): switch (event.value) {     case "Inpatient":         this.getField("SubProvType").setItems(["Hospice,Hospital,Nursing Facility"]);         break;     case "Outpatient":         this.getField("SubProvType").setItems(["Adult Day Center,Home,Other"]);         break;       case "Physician":         this.getField("SubProvType").setItems(["Surgeon,Family Practice,Neurologist"]);         br...

Likes

Translate

Translate
Adobe Community Professional ,
May 29, 2019 May 29, 2019

Copy link to clipboard

Copied

You used an invalid quotes mark here:

"200340-0207”

You must only use straight quotes.

Likes

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 29, 2019 May 29, 2019

Copy link to clipboard

Copied

Wow I didn't catch that! Thanks so much!

Likes

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 ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

My code for prompting certain dropdown lists based on what is selected in the first drop down seems to work great when I am on the "Preview" section of the "Prepare Form" on Acrobat Pro DC. Although what I am trying to initially use it for is on the Bluebeam Revu app and the functionality is messed up there.

Is there a way to fix this or a different app that I can download on iPad that will allow me to use all functionality of the form?

Likes

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
Adobe Community Professional ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

Your only chance of it working on an iPad is if you use PDF Expert by Readdle.

Likes

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 ,
Oct 15, 2015 Oct 15, 2015

Copy link to clipboard

Copied

Thank you to everyone in this thread, this saved me much frustration.

I was curious, is it possible to allow this validate script to edit multiple dropdowns. Meaning, dropdown 1 sets the contents of dropdown 2, however, can I make it so dropdown 1 sets the contents of dropdown 2, 3, 4 (dropdown 2, 3, and 4 would all have identical contents)? I understand I could do this by copying and pasting the "this.getField("XXX")" line and changing the field name every time. But, if there are say 10+ fields that I want a dropdown to effect, this can be cumbersome.

Thank you!

Likes

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
Adobe Community Professional ,
Oct 16, 2015 Oct 16, 2015

Copy link to clipboard

Copied

Sure, that's possible. Just add more lines with the appropriate setItems command.

Likes

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 ,
Oct 16, 2015 Oct 16, 2015

Copy link to clipboard

Copied

Hi try67,

Presently I create an array of what items I want in "setItems". This is what I have so far:

    case "P1": 

        this.getField("preflight.0.0").setItems(private);

        this.getField("preflight.1.0").setItems(private);

        this.getField("preflight.2.0").setItems(private);

        this.getField("preflight.0.1").setItems(private);

        this.getField("preflight.1.1").setItems(private);

        this.getField("preflight.2.1").setItems(private);

        this.getField("preflight.0.2").setItems(private);

        this.getField("preflight.1.2").setItems(private);

        this.getField("preflight.2.2").setItems(private);

Could this be consolidated onto one line perhaps? Just curious!

Thank you for your prompt reply!!

Likes

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
Adobe Community Professional ,
Oct 16, 2015 Oct 16, 2015

Copy link to clipboard

Copied

You can try this, but I doubt it will work:

this.getField("preflight").setItems(private);

Or even:

this.getField("preflight.0").setItems(private);

this.getField("preflight.1").setItems(private);

this.getField("preflight.2").setItems(private);

Likes

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 ,
Oct 16, 2015 Oct 16, 2015

Copy link to clipboard

Copied

No joy, thank you for your help sir!

Likes

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
Adobe Community Professional ,
Oct 16, 2015 Oct 16, 2015

Copy link to clipboard

Copied

Didn't think so... This is not one line, but it should work:

for (var i=0; i<=2; i++) {

    for (var j=0; j<=2; j++) {

        this.getField("preflight."+i+"."+j).setItems(private);

    }

}

Likes

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 ,
Oct 16, 2015 Oct 16, 2015

Copy link to clipboard

Copied

That is perfect! Thank you!!

Likes

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 19, 2015 Nov 19, 2015

Copy link to clipboard

Copied

Would this coding also work if I wanted to convert values from a dropdown to an abbreviation? Just store the abbreviation in a hidden text box and then leverage that value any time I need it?

Likes

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
Adobe Community Professional ,
Nov 19, 2015 Nov 19, 2015

Copy link to clipboard

Copied

Sure, that's possible...

Likes

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 19, 2015 Nov 19, 2015

Copy link to clipboard

Copied

Could you possibly assist me with this?

What I am trying to do is convert the value in the dropdown to a predetermined abbreviation. Then use that abbreviation as a component of a concatenate.

Likes

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
Adobe Community Professional ,
Nov 19, 2015 Nov 19, 2015

Copy link to clipboard

Copied

Place the abbreviation as the export value of the items in your drop-down and then you'll be able to use its value directly in your code.

Likes

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 19, 2015 Nov 19, 2015

Copy link to clipboard

Copied

Attached is the coding that I put into the custom validation script for the original dropdown. I named the placeholder dropdown "Store". The letters that I am using represent real values that I have inputted into my code. When I select any of those values in the original dropdown (Labeled "From (Provider)") nothing populates in the "Store" dropdown. Do you see something that I am doing incorrectly?

switch (event.value) { 

    case "A": 

        this.getField("Store").setItems(["B"]); 

        break; 

    case "D": 

        this.getField("Store").setItems(["E"]); 

        break;    

    case "R": 

        this.getField("Store").setItems(["S"]); 

        break;    

Likes

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
Adobe Community Professional ,
Nov 19, 2015 Nov 19, 2015

Copy link to clipboard

Copied

The code itself seems OK... Are there any error messages in the console when you change the value?

Can you share the file in question?

Likes

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 19, 2015 Nov 19, 2015

Copy link to clipboard

Copied

I appreciate the assistance but I would rather not share the contents of the file.

I am a novice when it comes to coding so I am not sure what you mean when you are asking if there are error message in the console. I am just using Adobe Form editor and there are no errors that pop up when I either enter the custom validation script or select the values in the dropdown that I placed into the code.

Ultimately, what I want to achieve is to convert the value in the dropdown to an abbreviation and then use that in a concatenate. I figured that using this dynamic dropdown was a workaround but if you could assist me with the question in the following thread I would appreciate it:

Changing the export value of a dropdown

Likes

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
Adobe Community Professional ,
Nov 19, 2015 Nov 19, 2015

Copy link to clipboard

Copied

Your code has nothing to do with your request (using an abbreviation in another field), so I can't really help you much with it, I'm afraid...

As I said before, if you set the abbreviation as the export value of your items then you could use the field's value directly.

Likes

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 19, 2015 Nov 19, 2015

Copy link to clipboard

Copied

I changed up the approach to using a dynamic dropdown because the answer was given to the original question.

When you say change the export value of the selection how would I exactly do that? Would it change what Adobe registers as the export value of the drop down and then when I use it in a concatenate it would take the abbreviation?

Likes

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
Adobe Community Professional ,
Nov 19, 2015 Nov 19, 2015

Copy link to clipboard

Copied

When you say change the export value of the selection how would I exactly do that?

Go to the field's Properties, Options tab. Select one of the items in the list and you'll see that it has two possible values: Item and Export Value.

The first is what is being displayed to the user. The second is the underlying value of the field when that item is selected.

Set the abbreviations as the latter.

Would it change what Adobe registers as the export value of the drop down and then when I use it in a concatenate it would take the abbreviation?

Yes.

Likes

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 19, 2015 Nov 19, 2015

Copy link to clipboard

Copied

WOW!

I feel incredibly silly. What a simple fix to the problem I have been having.

Thank you!

Likes

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 ,
Oct 02, 2016 Oct 02, 2016

Copy link to clipboard

Copied

How do you add a value to this item?

switch (event.value) {

    case "Inpatient":

        this.getField("SubProvType").setItems(["Hospice","Hospital","Nursing Facility"]);

        break;

    case "Outpatient":

        this.getField("SubProvType").setItems(["Adult Day Center","Home","Other"]);

        break;   

    case "Physician":

        this.getField("SubProvType").setItems(["Surgeon","Family Practice","Neurologist"]);

        break;   

}

Likes

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
Adobe Community Professional ,
Oct 03, 2016 Oct 03, 2016

Copy link to clipboard

Copied

Do you mean an export value to the items in the drop-down, or an additional item to the possible selections that you're setting, or a new "category", etc.? Please clarify.

Likes

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 ,
Oct 03, 2016 Oct 03, 2016

Copy link to clipboard

Copied

ill would like a value added to eg .. "hospice" with value of 2.

and "hospital" with value of 30.

Likes

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