4 Replies Latest reply on May 24, 2014 3:53 PM by try67

    show/hide fields when selecting an option from a drop-down menu.


      Hello Gurus!


      I have a question about creating a Java Script withing Acrobat pro.  This is what i would like to do: I created a drop-down menu with several selection entries.  Upon the customer making one of the selection entries, i would like for the correct fields that i created to become visible and all other fields to hide.  Is this even possible to do?  The reasoning behind this is because we have a form that customers have to generate in order to request access to certain financial accounts; we have over 20 different types of accounts and for each instance the customer has to fill out the same form.  By creating a drop down menu, i can use the same form by just changing the drop-down selection and clicking on the designated fields for that selection.  At this time i have over 20 different forms that poing to 20 different account requests and i would hate to send the form 20 different times to one person.  The reason i can not add all fields desired for all accounts is due to the fact that the form would be filled with hundreds of checkmarks and instructions thus making the process too tideous for the customer.  Hope you guys can help out.



        • 1. Re: show/hide fields when selecting an option from a drop-down menu.
          maxwyss Level 4

          The good news is, it can be done (and it has been done).


          There are a few things to be aware of, however.


          The most important is that the form must be planned well, which means that you must think carefully about your logic and even more so about your field naming (hierarchical field names are your friend). One fundamental issue, you have to be aware of, is that this form no longer will be a "standard form". The consequence of this is that you may have to be aware that you might get into trouble when you have to prove that your user filled out that particular standard form (talk to your compliance and forms management people about that).


          You also may have to decide whether the form should be usable in Reader. And, if so, how much you want to spend on the right to do so. You will see below why…


          There are actually two approaches for dynamically showing/hiding parts of a form. If your form can be separated between a fixed first page (where you also have the account type selection), and a variable part (depending on the selection), you could use Templates, which you spawn according to the selection, and delete pages when you change the selection. This approach is very easy to implement, but requires Reader Extensions Server to allow it to work in Reader; Acrobat Pro's extended rights are not sufficient for that.


          The other approach is showing/hiding fields. If you did your homework well, it would be very easy to first hide all subsequent fields, and then show the ones you need in two lines of code. This approach does not require extended rights for Reader at all, as long as your forms will always have the same number of pages, for each of your account types. This approach also works for the cases where the differences between the individual forms are very small. It does also work for showing/hiding bigger chunks of the form. In that case, you might create the "background" separately, and then put it as an icon into a button field which you will show/hide together with the carefully placed on top of it active fill-out fields.


          There is a third possibility, which Adobe Propaganda probably would suggest, and that woudl be subforms in LiveCycle Designer. The consequence is, however, that you won't have PDF forms, but proprietary XFA forms instead. And you may have more developing and maintenance work than with the other approaches.


          Back to your original question: you could use a Keystroke script evaluating event.changeEx of the combo box field. Depending on that, you would run your action to set up the according form part. The other way to do it would be evaluating event.value in the onBlur event. The latter would have the advantage that the selection has been made, and you get a bit more time to set up the form (this may in fact be an issue, particularly with Acrobat 9 and 10, which may take their time to show/hide fields).


          Another possibility instead of a drop down (combo box field) would be a popup, where you would have a button to press, and the list of selections pops up. This second method uses app.popUpMenuEx().


          Hope this can help.


          Max Wyss.

          • 2. Re: show/hide fields when selecting an option from a drop-down menu.

            The method below is vased on a combo box and using show/hide fields.  You would place this code in the custom format script section for the combobox.  The initial var's are your account fields.  Each case is an account type and by slecting which fields to show or hide you can thereby mangae what to fill.  You will  have to add the individual item name into the combobox to read exactly as the case name.  That way when you select it, it will run that specific part of script. You can further add more custom script to each case to suit your needs.  For example if you wanted the values of one of your text fields to prepopulate with a string or a value then within the case you would add,     f.value= "whatever";   and so forth.   Or if you had other comboboxes that should populate with other values then you would use  t.setItems([ ["$100.00", "100"], ["$200.00", "200"]]);  where T is the variable set for that combobox.  the first item is the string "$100.00" so the combobox will display as an option but the export value will be 100.  this will be useful if your form will be performing calculations.  Hopefully this gets you started.  


            • 3. Re: show/hide fields when selecting an option from a drop-down menu.
              Ali Haider shiblu Level 1


              i have a adobe livecycle form. i want to make a dynamic action here. there is a dropdwon list called relationship. there r 3 items here, SIMGLE, MARRIED AND DEFECTO. if i select married it needs to show a sub form containing partner details. subfom name is partner. if select DEFECTO also same action. but for Single I need it invisible. pls give a code and also details for it. file is here