Skip to main content
toddr14813053
Inspiring
September 19, 2017
Question

Long Drop Down List Show/Hide Field

  • September 19, 2017
  • 2 replies
  • 1844 views

I am creating a PDF Form in Acrobat Pro DC.  I have a list of over 40 items that I want in a drop down list that, when chosen, causes specific fields to appear or disappear.  I am already using the code shown below, but the validation section of the drop down properties states that my validation code is too long and cuts me off at just over 1100 lines.  Here are the questions that I can't find an answer to:

Is there a better way to: 1. create the drop down or 2. create the validation or 3. use a better form field option so that I can have this many items but still have it work in the file?  Everything must be part of the PDF file itself with no outside data source.  Maybe I'm just dreaming.

Here is what I've been using and it works great, but takes up too many lines of code once all 40 items are entered.

if (event.value == "Judge") {

    this.getField("Murray").display = display.hidden;   

    this.getField("Hunn").display = display.hidden;

........ // (Remainder of items)

}

else if (event.value == "Murray") {

    this.getField("Murray").display = display.visible;   

    this.getField("Hunn").display = display.hidden;

........ // (Remainder of items)

}

else (event.value == "Other") {

    this.getField("Murray").display = display.hidden;   

    this.getField("Hunn").display = display.hidden;

........ // (Remainder of items)

}

Thoughts?

Todd

This topic has been closed for replies.

2 replies

Inspiring
September 20, 2017

If you use hierachical naming for the fields you want to show/hide, you can hide them all with a single statement and show the one you want with a single statement. For example, if the fields were named: G1.Murray, G1.Hunn, etc., the code could be simplified to just:

// Hide all of the fields

getField("G1").display = display.hidden;

// Display the field corresponding to the selection

getField("G1." + event.value).display = display.visible;

toddr14813053
Inspiring
September 20, 2017

Ok, so the hide function works fine, but I have labeled the fields per your suggestion and then used your display line and they don't display.  This is what I'm showing now.

getField("G1").display = display.hidden;

getField("G1." + Murray).display = display.visible;

getField("G1." + Kress).display = display.visible;

getField("G1." + Hunn).display = display.visible;

getField("G1." + Laggis).display = display.visible;

getField("G1." + Hooste).display = display.visible;

getField("G1." + Smith).display = display.visible;

getField("G1." + Carnaroli).display = display.visible;

getField("G1." + Naftz).display = display.visible;

getField("G1." + Garbett).display = display.visible;

Inspiring
September 20, 2017

You'd have to do this:

getField("G1." + "Murray").display = display.visible;

or:

getField("G1.Murray").display = display.visible;

Bernd Alheit
Community Expert
Community Expert
September 19, 2017

For long code use an external JavaScript editor.

As validation you can use this:

.... set all fields as hidden ....

if (this.getField(event.value)) this.getField(event.value).display = display.visible;

toddr14813053
Inspiring
September 20, 2017

I have already opened with an if statement:

if (event.value == "Judge")

Does your suggested line replace my if statement?  If so, how do I reference the field name in the script?  Also how would I then set the fields to hidden if I am not referencing the field name?

I'm just not making the connection to how your suggested script figures into what I have done.