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

Create a dynamic dropdown field in Adobe Acrobat Pro XI

Explorer ,
Oct 30, 2014 Oct 30, 2014

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
75.6K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
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"]);

        break;  

}

View solution in original post

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

There obviously is an error with your code, or you wouldn't have gotten that error message...

Can you post your code?

Translate
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

Here is the code for when I type "1907" into the job number.

switch (event.value) { 

    case "1907": 

        this.getField("Cost Code2").setItems(["", "100050-0101", "101000-0101", "101400-0101", "103300-0101", "104000-0101", "107000-0103", "107300-0103", "107100-0106", "107400-0106", "107950-0107", "107000-0108", "107400-0108", "105200-0109", "200180-0109", "200420-0109", "107100-0110", "107500-0110", "200300-0201", "105100-0202", "200210-0202", "200420-0202", "200330-0203", "200320-0204", "105100-0205", "200260-0205", "200261-0205", "200420-0205", "200340-0207”, "200515-0208", "200516-0208", "200662-0209", "200661-0210", "200420-0301", "302000-0301", "302000-0303", "304000-0304", "302000-0305", "302000-0306", "302000-0307", "301000-0308", "200570-0309", "502000-0401", "502000-0402", "502000-0403", "502000-0404", "503000-0404", "502000-0405", "503000-0405", "502000-0406", "402000-0407", "402000-0408", "403000-0408", "402000-0409", "402000-0410", "404000-0410", "402000-0411", "200200-0412", "200570-0412", "502000-0413", "502000-0414", "301000-0415", "200570-0416", "200570-0417", "301000-0418", "702600-1001", "107100-1002", "107500-1002", "701800-1003", "200910-1004", "105400-1005", "200010-1005", "200420-1005", "105100-1006", "200210-1006", "200420-1006", "302000-1007", "302000-1008", "303000-1008", "302000-1009", "303000-1009", "302000-1010", "303000-1010", "105300-1011", "200110-1011", "200420-1011", "107100-1012", "107200-1012", "302000-1014", "106100-1015", "106100-1016", "501000-1017", "502000-1017", "503000-1017", "301000-1026", "200570-1027", "200661-1028", "200662-1029"]); 

        break;

 

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

You used an invalid quotes mark here:

"200340-0207”

You must only use straight quotes.

Translate
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

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

Translate
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

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?

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

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

Translate
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

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!

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

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

Translate
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

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!!

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

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

Translate
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

No joy, thank you for your help sir!

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

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

    }

}

Translate
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

That is perfect! Thank you!!

Translate
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

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?

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

Sure, that's possible...

Translate
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

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.

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

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.

Translate
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

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;    

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

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?

Translate
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

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

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

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.

Translate
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

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?

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

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.

Translate
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

WOW!

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

Thank you!

Translate
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

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;   

}

Translate
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