Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


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

51.7K

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 ,
Oct 30, 2014 Oct 30, 2014

Copy link to clipboard

Copied

Is this an LCD 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
Explorer ,
Oct 30, 2014 Oct 30, 2014

Copy link to clipboard

Copied

Gilad D... no, I am creating the form in Adobe Acrobat XI Pro.

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 30, 2014 Oct 30, 2014

Copy link to clipboard

Copied

Then you have quite a few mistakes in your code. First of all, to access a field you must use the getField method. Also, there's no such property called rawValue. You should use value or valueAsString. Also, the setItems method takes an array of strings as its single parameter, not multiple string parameters.

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
Explorer ,
Oct 30, 2014 Oct 30, 2014

Copy link to clipboard

Copied

Thanks for your reply Gilad D. The code that I was using, in going back and looking, was for LiveCycle.... I was guessing that it would be the same. I will do some more digging with your suggestions. I understand what you are saying, but I honestly have no idea how to put it all together to make it work. Is there a tutorial that you know of that might help me out? I'm interesting in figuring this out, I just don't know where to start 😕

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 30, 2014 Oct 30, 2014

Copy link to clipboard

Copied

Have a look at these tutorials:

https://acrobatusers.com/tutorials/js_list_combo_livecycle

https://acrobatusers.com/tutorials/list_and_combo_in_lc

On Thu, Oct 30, 2014 at 8:39 PM, aimee_boise <forums_noreply@adobe.com>

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
Explorer ,
Oct 30, 2014 Oct 30, 2014

Copy link to clipboard

Copied

I am still having no luck. I have read Thom Parker's Programming List and Combo fields part 1 and have tried to follow the AcroForm document example that he used in the tutorial to make my form work, but the tutorial example is so much more complicated than the 2 fields that I need, and I cannot follow it. His documentation is awesome, but I just can't wrap my head around it. I am now guessing that this must not be as simple as adding a JavaScript action to a field in Acrobat 😕 Are there any other suggestions or code that someone might be willing to help me with?

I did find a forum question, Auto-Filling a Drop down List with a Drop down List (JavaScript), that had an answer also by Thom Parker, that stated it would work with something simple:

var oSelListItems = {"aa":[1,2,3,4], "bb":[5,6], "cc":[7,8,9]};

However, I still am unsure where to add this, or if this is all the form will need. (The first part of the tutorial example no longer exists on that site, so I could not follow along.) Does anyone know if this would work for my scenario?

Thanks again in advance for any help and/or coding anyone can pass along.

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 30, 2014 Oct 30, 2014

Copy link to clipboard

Copied

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

        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
Explorer ,
Oct 31, 2014 Oct 31, 2014

Copy link to clipboard

Copied

Gilad D...THANK YOU SO MUCH! With a little modification, this is working perfectly!

I modified the setItems so that they would come up as individual items on the second dropdown list:

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;    

}

I can't thank you enough! Now I have this working and I can build from it, adding (many) new main and sub types (there are around 80), and also figure out how to have a "-----" (none) selected, but I am confidant I can do that. Thank you again 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
Adobe Community Professional ,
Oct 31, 2014 Oct 31, 2014

Copy link to clipboard

Copied

Just add it as the first item in the list. It will be the default item that

way.

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 31, 2014 Oct 31, 2014

Copy link to clipboard

Copied

I am trying to do something very similar.  I am not a script writer at all so I was happy to find this thread.  I copied the information from this to try to create by own script and I am running into issues when I copy the information to Adobe.  It is not validating.  Could you please assist me?  I am building a change of curriculum form for the university.  I want the student's selection of their NewMajor to Populate the choices they get for the Concentration.  When I copied this information into the JavaScript Editor in Adobe Forms I get an Error Message "SyntaxError: invalid switch statement 2: at line 3.  Any help would be greatly appreciated.

switch (event.value) { 

    NewMajor "BA - Communication (BACOMM)": 

        this.getField("Concentration").setItems(["Select One,None,Mass Communication (MCO1),Theatre (THEA),Communication Studies (MC02)"]); 

        break; 

    NewMajor "BA - History (BAHIST)": 

        this.getField("Concentration").setItems(["Select One,None,Teacher Certification (HIS1)"]); 

        break;    

    NewMajor "BBA - Business Administration (BBA-BADM)": 

        this.getField("Concentration").setItems(["Select One,None,Supply Chain Management (SCM),Hospitality Management (HSMG)"]); 

        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
Explorer ,
Oct 31, 2014 Oct 31, 2014

Copy link to clipboard

Copied

dbettis2.... Please understand that everything I am about to tell you is ONLY thanks to the help I received from Gilad D. I don't know if this will help you or not, but I want to try and pass it forward.

If what you are looking to do is have two dropdown fields, and the second one (concentration) be a list determined by what was chosen in the first one (newMajor) then this will work, if you are using Adobe Acrobat Pro.

Create a dropdown field and name it newMajor. In the "options" tab. Make sure that you enter all of the items that you want in that list AND that they match the javascript (or this will not work.)

In this case, I believe you want the initial list to be:

- Select One -

BA - Communication (BACOMM)

BA - History (BAHIST)

BBA - Business Administration (BBA-BADM)

After you create the dropdown field and enter all of the options, go to the Validate tab, chose "run custom validation script", then copy and paste the following:

switch (event.value) {

    case "- Select One -":

        this.getField("Concentration").setItems(["-----"]);

        break;

    case "BA - Communication (BACOMM)":

        this.getField("Concentration").setItems(["- Select One -","None","Mass Communication (MCO1)","Theatre (THEA)","Communication Studies (MC02)"]);

        break;

    case "BA - History (BAHIST)":

        this.getField("Concentration").setItems(["- Select One -","None","Teacher Certification (HIS1)"]);

        break;

    case "BBA - Business Administration (BBA-BADM)":

        this.getField("Concentration").setItems(["- Select One -","None","Supply Chain Management (SCM)","Hospitality Management (HSMG)"]);

        break;

}

Then create a second dropdown field, and name it Concentration. Nothing further needs to be done with the second dropdown field (as far as entering options or any javascript.)

It should work. I have created a form using this code and field structure, and it is working. I hope this helps you, if in fact this is what you were trying to do. (I do not know how to attach a file to this post or I would send you the PDF that I made so you could see the fields. If you message me, I can send it to 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
Community Beginner ,
Nov 03, 2014 Nov 03, 2014

Copy link to clipboard

Copied

That worked perfectly!!!  Thank you so much for the assistance!!


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 ,
Aug 31, 2018 Aug 31, 2018

Copy link to clipboard

Copied

I am trying to do something similar; with the first drop down menu being a list of numbers (1-57) and then I want the second drop down menu to give a list of different violation codes that can be chosen. For example If someone chooses #1; I want the second drop down menu to give these options to choose from 2-101.11(A),(B) PIC is present, 2-102.11(A),(B) No P violations or certified manager, 2-102.11(C),(1),(4-16) EHS-Questions & PIC Answers, 2-103.11(A)-(O) PIC duties

I would appreciate any guidance you can give me on this. I have tried using the same steps as you have given, but it keeps giving me a syntax error

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

Copy link to clipboard

Copied

@aimee_boise Sorry to ressurect such an old thread, but I'd ike to thank you for your clear explanation of the steps you had yourself learned!

It turned out that the problem I'd been having was trying to put the validation script in the second drop down box, not the first one, which I now understand 'pushes' the info into the second drop down, as opposed to simply not displaying the options that apply only to the other options in box 1.

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 ,
Jun 07, 2021 Jun 07, 2021

Copy link to clipboard

Copied

Hello,

 

I am trying to acheive something similar with 3 drop-down menus: L0 determinses values in L1 which determines values in L2.

 

L0

-Direct

-Indirect

-Misc

 

L1 (Direct)

-Collection Materials

-Fleet

-Fuel & Chemicals

 

L2 (Collecion Materials)

-Containers

-Drums

 

I do not have any script writing skills so detailed explainiantion will be apprecaited. I will be grateful if you coudl share your PDF for me to undertsnad the script. 

 

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 08, 2021 Jun 08, 2021

Copy link to clipboard

Copied

LATEST

Here's an article that shows the exact steps to create a 2 tiered dropdown dependency and provides an example. The pattern of the 2 combo solution can be easily extended. 

 

If you don't want to work out the scripting yourself, then you should consider hiring a developer. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Aug 31, 2018 Aug 31, 2018

Copy link to clipboard

Copied

I am trying to do something similar; with the first drop down menu being a list of numbers (1-57) and then I want the second drop down menu to give a list of different violation codes that can be chosen. For example If someone chooses #1; I want the second drop down menu to give these options to choose from 2-101.11(A),(B) PIC is present, 2-102.11(A),(B) No P violations or certified manager, 2-102.11(C),(1),(4-16) EHS-Questions & PIC Answers, 2-103.11(A)-(O) PIC duties

I would appreciate any guidance you can give me on this. I have tried using the same steps as you have given, but it keeps giving me a syntax error

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 ,
Jan 02, 2017 Jan 02, 2017

Copy link to clipboard

Copied

I'm attempting to do something similar, but not quite what the original post needed help with. I tried to modify this script, but as I have zero experience working with scripts, it isn't working for me.

I'm trying to build an invoice for set items, so the item description column has a dropdown list of the items we offer. I'd like to be able to choose an item, and then in the next column have the price associated with that item show up. I attempted to change the script so that it looked like this:

switch (event.value) { 

    case "12x18_Mohawk_100C_Coated": 

        this.getField("COSTRow1").setItems(["0.15"]); 

        break; 

but I'm not sure how I need to format the COSTRow1 box in order for it to show the price associated with the above script.

Or the above script could be intended solely for an additional dropdown and that's my problem. Again: zero experience. Would love some guidance!

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 ,
Jan 03, 2017 Jan 03, 2017

Copy link to clipboard

Copied

Is the cost field a drop-down? If so, why? I think it makes more sense to use a text field, and then you can use this code to populate it with the value and the Format setting will take care of the rest:

this.getField("COSTRow1").value = 0.15; 

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 ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

I hope you can help walk me through this process in a little more detail.  I am trying to dynamically link two drop down menus in adjacent columns. 

In other words, I have 4 major programs in one dropbown list; and, 4 dropdown lists of departments for each program.  Once you select a program from the dropdown list, then I want to have the only corresponding dropdown list of departments appear in the adjacent box.

1 Direccion Superior

2 SEE

3 SEAF

4 SET

For the sake of example:

Program1 has 13 Departments

Program 2 has  7 departments

Program 3 has 9 departments

Program 4 has 7 departments

I have seen the prior scripts that you have listed above but i do not know how or where to write this and what steps i need to take.

Thank you in advance.

Julio

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 ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

You can use this tool I've developed for exactly this kind of task: Custom-made Adobe Scripts: Acrobat -- Create Dependent Dropdowns

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 ,
Jul 12, 2017 Jul 12, 2017

Copy link to clipboard

Copied

This has been a really helpful thread for trying to get some validation. I am having some trouble extending this out to multiple dropdowns and some help would be awesome.

I am trying to do something a little different with validation based on the primary dropdown selection, feeds into 3 sub dropdown boxes.

Scenario, each site has a different number if buildings,If someone selects wellington, then they get Building one, two and 3, and they have floor 1-10 and room 1-100. if Auckland is selected they have only buildings 1-2 and floor 1-5 and room 1-50 etc...

e.g.

First dropdown (City)

Wellington

Auckland

Christchurch

Second dropdown (Site)

Building 1

Building 2

Building 3

Third dropdown (Floor)

Floor 1

Floor 2

Floor 3

Fourth dropdown (Room)

Room 1

Room 2

Room 3

For the first dropdown I have the starting code as below which will work for the second dropdown, bit I have tried adding other lines to make the third and 4th dropdowns, but it gives me an error saying a ] is missing. Should I just be able to add the following to the original code?:

    case "Wellington":

        this.getField("Floor").setItems(["- Select One -","None","1","2","3"]);

       break;

switch (event.value) {

    case "- Select One -":

        this.getField("Site").setItems(["-----"]);

        break;

    case "Wellington":

        this.getField("Site").setItems(["- Select One -","None","Building 1","Building 2","Building 3"]);

       break;

    case "Auckland":

        this.getField("Site").setItems(["- Select One -","None","Building 1","Building 2"]);

        break;

    case "Christchurch":

        this.getField("SIte").setItems(["- Select One -","None","Building 1",]);

        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 ,
Jul 13, 2017 Jul 13, 2017

Copy link to clipboard

Copied

In the last setItems command, remove the last comma.

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 ,
Feb 22, 2018 Feb 22, 2018

Copy link to clipboard

Copied

Hello,

I am new to script writing and I am seriously struggling.

I am trying to create a form in Acorbat where if one division is selected than the relevant position titles will generate in another dropdown. if someone could please give me a brief explanation on how to do this that would be greatly appreciated.

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