Conditional Drop Down Help

I would either like one drop down selection to impact the available options in the next drop down OR if it is easier use a radio button to select one of two categories which would then only show the relevant options in the next drop down field. Please help! I have seen similar posts but nothing exactly like this.


Megan Krat


3 Answers

Voted Best Answer

You can use one dropdown to control a second dropdown control. There are a number of examples here on this site. This tutorial demonstrates the mechanism in general (one dropdown controls another field): https://acrobatusers.com/tutorials/change_another_field

Let's assume you have two dropdown named "Dropdown1" and "Dropdown2". When you use the following as the custom validation script for "Dropdown1", you can set the options for Dropdown2:

var options = {
  "One" : [ "one.1", "one.2", "one.3" ],  
  "Two" : [ "two.1", "two.2", "two.3" ],  
  "Three" : [ "three.1", "three.2", "three.3" ],
};

this.getField("Dropdown2").setItems(options[event.value]);

You may also want to set "Commit selected valued immediately" for Dropdown1 on it's "Options" panel.

Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
http://www.khkonsulting.com


By Karl Heinz Kremer   

Doing it for 2 drop-downs is pretty straight forward (if you know how to write or edit JS code), but if you want to do it to three levels or more it becomes much more complex. In that situation (or even just with two fields, if you don't want to mess around with tweaking code examples), you can use this tool I've developed: Acrobat -- Create Dependent Dropdowns

.


Visit my custom-made PDF scripts website: http://try67.blogspot.com
Contact me personally: try6767@gmail.com


Gilad D (try67)   

That's done in the "options" data structure: The element before the ':' (e.g. "One") is the value that gets selected in Dropdown1, and the elements after ':' (e.g. " [ "one.1", "one.2", "one.3" ]" are the option you want to make available for selection in Dropdown2.

What you want to do is a bit more complex, and would require a slightly different approach.

To hide dropdown2 (or set it to readonly), you would add more code to the custom validation script. You can for example use the following (just set the values in Dropdown3 instead of Dropdown2 - I also renamed the options data structure so that you can also have one called transactionOptions):

var litigationOptions = {
  "One" : [ "one.1", "one.2", "one.3" ],  
  "Two" : [ "two.1", "two.2", "two.3" ],  
  "Three" : [ "three.1", "three.2", "three.3" ],
};

if (event.value != " ") {
    this.getField("Dropdown2").readonly = true;
    this.getField("Dropdown3").setItems(litigationOptions[event.value]);
} 
else {
   this.getField("Dropdown2").readonly = false;
   this.getField("Dropdown3").clearItems();
}

Do something very similar with Dropdown2, just set Dropdown1 to readonly and use a different set of options for Dropdown3.

Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
http://www.khkonsulting.com


Karl Heinz Kremer   


Please specify a reason: