Skip to main content
Participating Frequently
September 1, 2020
Answered

Cascading / Dependent dropdown lists using Acrobat DC Standard

  • September 1, 2020
  • 3 replies
  • 8777 views

Hi,

 

I have tried searching a lot and am yet to come across a self-help solution/code to create cascading / dependent dropdown lists (Combo box) using Acrobat DC Standard. 

 

The closest match I found was a Creative Commons Custom Format free script (can't seem to find the link now) which had a bug where in the form resets when it is saved and reopened. 

 

Would appreciate any other suggestions.

 

 

This topic has been closed for replies.

3 replies

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
September 1, 2020
veryviralAuthor
Participating Frequently
September 4, 2020

This is perfect. Thanks a ton!

 

I had found an older version of this file which had a bug that reset the dependent combo box selection after saving, closing and reopening the file. The one you have shared seems to be working well. 

 

Thank you to all who contributed.

Known Participant
January 19, 2022

Now if ionly i can get a third box that is cascaded by what is selected in the second box, lol!

try67
Community Expert
Community Expert
September 1, 2020

If you're interested I've created a (paid-for) tool that allows you to set it up very easily (based on a spreadsheet) without having to write any code. You can find it here: http://try67.blogspot.com/2014/11/acrobat-create-cascading-dropdowns.html

Thom Parker
Community Expert
Community Expert
September 1, 2020

You'll find solutions here:

https://acrobatusers.com/tutorials/js_list_combo_livecycle/

This solution shows how the basic operations are handled. However, dependent series of lists create a state problem, because the state of the current list entered into the down stream list field is maintained dynamically in the code. This state is lost when the field is closed.  This is not a bug, it's an incomplete solution. There are two easy solutions for restoring this state. One is to follow the selection chain to restore the dynamic state. The second is to save the dynamic state as JSON in a hidden text field.  Ideally, you'd use an object at runtime to maintain this state. 

 

You'll find a more advanced solution here as well as a ton of scripts and sample PDFs(but it is not free):

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

The solutions presented here are more advanced and include a statmp      

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
veryviralAuthor
Participating Frequently
September 1, 2020

Thank you for your response. 

 

Due to my limited understanding of JavaScript, I searched for another logical but easier way to solve this via Show/Hide dropdown lists and came across this linkIn the options panel, check the box that says "Commit selected value immediately" then add your code to the Custom Format Script of the Master dropbox.

 

Sample I customised to suit my need (posting here to assist others) that seems to be working well so far:

Note that everything after "//" are comments for you to understand the code. Append IF and Else statements similarly for additional dependent dropdown fields that you'd like to show/hide. The only downside I can think of is that I need to create as many dependent Combo Box fields as the number of options in the Master List. Welcome all constructive feedback. 

 

var v = this.getField("MasterList").value; //Replace MasterList with the Master/predecessor field name
if (v === "Option1") { //Replace Option1 with the first dropdown option value from the MasterList
this.getField("ComboBox1").display = display.visible; //Replace ComboBox1 with the first Combo Box (Dropdown list) field name
}
else {
this.getField("ComboBox1").display = display.hidden;
}
if (v === "Option2") {
this.getField("ComboBox2").display = display.visible;
}
else {
this.getField("ComboBox2").display = display.hidden;
}

 

 

Thom Parker
Community Expert
Community Expert
September 1, 2020

Showing and hiding fields is a solution to a different problem than the dependant dropdown problem you asked about. If you want help you need to describe the actual problem you are trying to solve (which you still haven't done).  Here's an article on everything you need to know about hiding and showing fields.

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm?sd=40

 

 

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