Skip to main content
gamzes93533812
Known Participant
November 16, 2017
Question

ListBox item selection to show/hide (several) other form fields

  • November 16, 2017
  • 1 reply
  • 1501 views

Salut!

I am preparing a form in Acrobat. I have a listbox (e.g., ListBox1) with 10 items (e.g., item1, item2, item3). I would like to show/hide other form fields (that I already created) dynamically according to users selection from the listbox.

For example, if user selects "item1" from ListBox1, I will display only form field#1 or if user selects item2 from ListBox1, I will display only form field#2, and so on...

 

I will be really looking forward for any suggestions/corrections.

------

PS. I used the following amongst others for my ListBox1:

if(event.value !="item1") {

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

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

}

else if (event.value !="item2")

{

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

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

}

else if.....

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
November 16, 2017

In which event did you put this script?

The best way to setup a list is to set the "Commit immediate" option and then use the "Custom"  Keystroke Event Script on the "Format" tab.

Start you script like this

if(event.willCommit)

{

  ... your existing code ...

}

Use the console to display key values you need to determine whether or not the script is working.

Here is an article and a video you'll find useful

https://acrobatusers.com/tutorials/js_list_combo_livecycle

https://www.pdfscripting.com/public/images/Free_Videos/BeginJS_Console_Alt_mp4.cfm

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
gamzes93533812
Known Participant
November 16, 2017

Thank you @Thom for advices. I will check them, and write my experience accordingly.

One simple issue: I put the script in MouseUp event. After reading your comment I see it's a problem.

Thom Parker
Community Expert
Community Expert
December 1, 2017

Here's another article that will be helpful in list programming.

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

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