7 Replies Latest reply on Jun 13, 2013 5:25 AM by Haiko Oosterbaan

    Dependent dropdown lists in Acrobat

    Scottbrander Level 1

      Hi,

       

      I am a first time poster and was looking for help with some scripting in a PDF form I have created.

       

      I am basically looking to have a second dropdown list dependant on the value of the first but I'm not having any success.

       

      I have tried the following as a calculation and as a MouseUp Javascript action but to no avail.

       

      Basically, I'm looking for the following: If a user selects a School/Unit called Registry in dropdown 1, it will populate with 4 or 5 locations in dropdown 2. I need to do this for about 20 units. I think I'll be ok once I get one unit working but I can't get to that stage

       

      
      // clear the dropdown displayed value and items
      this.Value = null; 
      this.clearItems();
      
      
      // repopulate the items based on the checkboxes 
      if(this.getField("School/Unit").Value == "Registry")
      {
           this.addItem("Location 1");
           this.addItem("Location 2"); 
           this.addItem("Location 3"); 
           this.addItem("Location 4"); 
           this.addItem("Location 5"); 
      
      }
      
      

      Can anybody help me please?

       

      Many thanks

      Scott

        • 2. Re: Dependent dropdown lists in Acrobat
          Scottbrander Level 1

          Hi,

           

          Thank you for your help but this does not really answer my question. I was looking to cascade a second combo box from the result of the first one, however this page answers how to populate a text field from the combo box. A user did ask in the questions below for help but wasn't answered.

           

          Can you help further?

           

          Thanks

          Scott

          • 3. Re: Dependent dropdown lists in Acrobat
            Plstsn Level 3

            I suggest you try using the popUpMenuEx or the popUpMenu.

            You can read more about them in the Javascript reference under application methods.

             

            I'm sure the popUpMenuEx will give you the desired result.

             

            Torben.

            • 4. Re: Dependent dropdown lists in Acrobat
              Scottbrander Level 1

              Hi Torben,


              Many thanks for your help. Does the popUpMenuEx require that the two dropdowns need to be next to each other? The dropdowns on my form have to be in two different sections and I thought I might get it to work with the code in my Original Post or similar.

               

              The popUpMenuEx might be useful for another field though so thanks for the heads-up.

               

              Many thanks

              Scott

              • 5. Re: Dependent dropdown lists in Acrobat
                Plstsn Level 3

                Hi Scott.

                Popup menus are not combo boxes - but menus that popup and act like a horizontal flyout menu. You can make a hierarchic structure, and that was what I thought you were looking for.

                 

                But now I think I got the picture of what your question was all about.

                 

                As posted by try67, the article from acrobatusers.com does actually provide you with an answer - but of course, not an exactly solution for your specific case. You'll have to transfer the way of thinking to satisfy your needs.

                 

                 

                Ex:

                Let's say you have two combo boxes - box1 and box2.

                And let's give box1 3 chooses: Blank, a and b.

                If user chooses option a, box2 will contain choices C and D.

                If user chooses option a, box2 will contain choices E and F.

                Remember to check the "Commit selected value immediately" for the boxes.

                 

                In box1 you use the keystroke script from the article and modify it:

                 

                if( event.willCommit )

                {

                   if(event.value == "")

                     //if nothing is chosen in box1 then box2 will be cleared

                     this.getField("box2").clearItems();

                   else

                    SetFieldValues(event.value);

                }

                 

                Then you have to modify the document script from the article a little bit.

                 

                //First you make the values for box1.

                myBox1Values = ["", "a", "b"];


                //Then you populate the values to box1.

                this.getField("box1").setItems(myBox1Values);



                // Then you define what has to be shown in box2 when value is selected

                var DeptData = { a: ["C","D"],

                                 b: ["E","F"]

                                };


                //Finally you set the values of box2

                function SetFieldValues(cDeptName)

                {

                  this.getField("box2").setItems(DeptData[cDeptName]);

                }

                 

                That's all you need.

                Now you just have to transfer (almost copy/paste) this to your document.

                 

                And so the article did actually give you the answer - just a matter of looking.

                 

                Torben.

                 

                 

                 

                • 6. Re: Dependent dropdown lists in Acrobat
                  Scottbrander Level 1

                  Hi,

                   

                  Maybe it was my complete lack of Javascript skills but I could not originally see the answer on the page for my particualr query but you have all been a great help.

                   

                  Thanks again

                  Scott

                  • 7. Re: Dependent dropdown lists in Acrobat
                    Haiko Oosterbaan Level 1

                    Hi,

                     

                    The explanation above was very helpful in setting up dependent dropdown lists.

                    The problem I'm having now is how to adjust the script to be able to have multiple of these dependent dropdown lists on one page, which all can be used separately.

                    I tried giving the second set of boxes this code:

                     

                    keystroke script:

                     

                    if( event.willCommit )

                    {

                       if(event.value == "")

                         //if nothing is chosen in box3 then box4 will be cleared

                         this.getField("box3").clearItems();

                       else

                        SetFieldValues(event.value);

                    }

                     

                    and adjusted the document Javascript:

                     

                    //First you make the values for box1&3.

                    myBox1Values = ["", "a", "b"];

                    myBox3Values = ["", "a", "b"];

                     

                    //Then you populate the values to box1&3.

                    this.getField("box1").setItems(myBox1Values);

                    this.getField("box3").setItems(myBox3Values);

                     

                    // Then you define what has to be shown in box2 and box4 when value is selected

                    var DeptData = { a: ["C","D"],

                                     b: ["E","F"]

                                    };

                     

                    //Finally you set the values of box2 and box4

                    function SetFieldValues(cDeptName)

                    {

                      this.getField("box2").setItems(DeptData[cDeptName]);

                      this.getField("box4").setItems(DeptData[cDeptName]);

                     

                    }

                     

                    This doesn't work. When changing the value in box1 or box3, both box2 and box4 change.

                     

                    Has anyone got an idea how to solve this?

                     

                    Thanks, Haiko.