3 Replies Latest reply on Feb 12, 2014 4:39 AM by Dimlite

    JavaScript: Use a dropdown to change visibility of other fields

    Dimlite

      Hello

      I'm new here and hope you can help me.

      I have no JavaScript experience. I've tried a lot, but it doesn't work so far.

      I use Adobe Acrobat X (Version 10.1.9).

       

      My idea:

      A User should select his country in a dropdown. Depending on the user's selection, appears another dropdown. If no country is selected, no other dropdown is visible.

      When the user select the country "England" the dropdown "EnglandAreas" should get visible.

      When the user select the country "Scotland" the dropdown "ScotlandAreas" should get visible.

      etc

       

      Now I think there are two ways.

      1. For each country it has an own area dropdown. When the user opens the document, all area dropdowns are hidden. The User select his country and a JavaScript set the correct area dropdown visible.

      2. For all countries there is one area dropdown. When the user opens the document, the area dropdown is hidden. The User select his country and a JavaScript fills the area data of the selected country in the area dropdown and set the area dropdown visible.

       

      Which method makes more sense or is there a third method?

       

      One of my non-working code (try method 1):

      var co = this.getField("Country");

      var aren = this.getField("AreaEN");

      if (co== "England") {

      event.value = (aren.display = display.visible)

      } else {

      event.value = (aren.display = display.hidden)

      }

       

       

      Thanks for all the help.

        • 1. Re: JavaScript: Use a dropdown to change visibility of other fields
          George_Johnson MVP & Adobe Community Professional

          Where is that code placed, exactly? It should be something like this:

           

          // Get a field value and a field object

          var co = this.getField("Country").valueAsString;

          var aren = this.getField("AreaEN");

           

          // Set the visibility of the AreEN field based on the selected value

          if (co == "England") {

              aren.display = display.visible;

          } else {

              aren.display = display.hidden;

          }

           

           

          But the correct code does depend on where it's placed.

          1 person found this helpful
          • 2. Re: JavaScript: Use a dropdown to change visibility of other fields
            Dimlite Level 1

            I placed the code in the Properties of the main dropdown "Country", in the tab Format under Custom Keystroke Script.

             

            I tried it with your code. The AreaEN field sometimes becomes visible, but never when I have selected "England".

             

            At my first try I forgot the "valueAsString".

            Recognize the code, which selection I have chosen in the main combo?

            • 3. Re: JavaScript: Use a dropdown to change visibility of other fields
              Dimlite Level 1

              If I select "England" the field "AreaEN" becomes not visible.

              Afterwards it doesn't matter, which other country I select, the field "AreaEN" becomes visible.

              Now i can select the every country, the field stay not visible. Until I select "England" again (at this point the field is still not visible). After the selection of "England" I can select every other country and the field becomes visible again.

               

              It seems as the selection is not applied immediately.

               

              The “Commit selected value immediately” option is checked.