12 Replies Latest reply on Oct 21, 2014 12:51 PM by Acduffell

    Populating drop down lists

    Acduffell

      Greetings

      I have created a form in Acrobat XI Pro with 3+ text fields which populate a drop down list.  My problem is that when I duplicate the Drop down, which I need to do around 50 times, each selection resets all the drop downs to that choice.

      The Drop down fields have a Javascript action added to call a single Javascript. 

      function popDropdown()

      {

       

       

          var myBlocks = [];

           {

              myBlocks.push("Select from Drop down");

          }

        

          if (this.getField("Block1").value != "")

          {

              myBlocks.push(this.getField("Block1").value);

          }

         

          if (this.getField("Block2").value != "")

          {

              myBlocks.push(this.getField("Block2").value);

          }

         

          if (this.getField("Block3").value != "")

          {

              myBlocks.push(this.getField("Block3").value);

          }

       

       

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

          this.getField("select").setItems(myBlocks);

        

      }

        • 1. Re: Populating drop down lists
          Karl Heinz Kremer Adobe Community Professional

          When you duplicate a field, all field properties are shared among these

          copies. This means that when you change one field, all other fields that

          share that name will also show that change. This is how you get for example

          a name that you enter on the first page of a document to a field on page

          100: You just create a text field one page 1, and one on page 100 that use

          the same name. The user only has to fill in the data once, and it gets

          automatically propagated to all fields that share that name.

           

          I assume you've used copy&paste to duplicate your dropdown control. That

          copies everything, including the name. So all your copies share the same

          name, and all of them get updated when you update one.

           

          What you need to do is open up the preferences for each of these duplicates

          and provide a unique name for each. You can also do this in the list of

          fields on the Forms panel once you are in forms editing mode.

          • 2. Re: Populating drop down lists
            Acduffell Level 1

            Thanks for that.  If I have a unique name for each drop down field won't that mean I have to duplicate the script for every one to suit the unique name?  Ref: last 2 lines of script.

            • 3. Re: Populating drop down lists
              Karl Heinz Kremer Adobe Community Professional

              Yes, you would have to execute these two lines for every dropdown you have. This does not necessarily mean that you have to duplicate the two lines, you can execute them in a loop. Something like this would work:

               

              var lDropdowns = [ "Dropdown1", "Dropdown2", "Dropdown3"];
              
              // ...
              
              for (var i in lDropdowns) {
                  this.getField(lDropdowns[i]).clearItems();
                  this.getField(lDropdowns[i]).setItems(myBlocks);
              }
              
              1 person found this helpful
              • 4. Re: Populating drop down lists
                Acduffell Level 1

                Have added the extra script but can't get it to work.  What does the "l" character in front of "Dropdowns" do?  This does not seem to translate correctly in my font.

                • 5. Re: Populating drop down lists
                  Karl Heinz Kremer Adobe Community Professional

                  I declared a variable that contains a list. I use a lower case "L" as the

                  first character in a variable name to indicate that I am dealing with a

                  list. You can name the list anything you want.

                  • 6. Re: Populating drop down lists
                    Acduffell Level 1

                    Great.  Working now but when I select on Dropdown1, Dropdown2 & 3 reset to the default value and so on.

                     

                    Any ideas?

                    • 7. Re: Populating drop down lists
                      Karl Heinz Kremer Adobe Community Professional

                      No, not without seeing your document.

                      • 8. Re: Populating drop down lists
                        Acduffell Level 1

                        Have a mock up "Test" document I can send.  What would be the best way to send?

                        • 9. Re: Populating drop down lists
                          Karl Heinz Kremer Adobe Community Professional

                          Upload it to a file sharing site (e.g. Acrobat.com or Dropbox.com) and then

                          post the link here. If you cannot share publicly, you should not have any

                          problems finding my email address, it's all over the internet

                          • 10. Re: Populating drop down lists
                            Acduffell Level 1

                            Here's the link: http://adobe.ly/10fRYYB

                             

                            Thanks Karl

                            • 11. Re: Populating drop down lists
                              Karl Heinz Kremer Adobe Community Professional

                              Here is the problem: You are modifying the dropdown configuration every time somebody moves the mouse over one of the dropdowns. Every time you set the data in the dropdown list, it will always reset the selection to the first item.

                               

                              I would remove all embedded JavaScripts, and all "On Focus" triggers for the dropdowns and the text fields. Then create a new text field that uses the following script as it's custom calculation script:

                               

                              // global calculation script
                              
                              // take the information from Block1..Block3 and
                              // initialize the dropdown lists
                              
                              var aDropdownListData = [];
                              aDropdownListData.push("Select from Drop down");
                              aDropdownListData.push(this.getField("Block1").value);
                              aDropdownListData.push(this.getField("Block2").value);
                              aDropdownListData.push(this.getField("Block3").value);
                              
                              var lDropdowns = ["select1", "select2", "select3" ];
                              
                              for (var i in lDropdowns) {
                                // get the currently selected item in the dropdown list
                                var f = this.getField(lDropdowns[i]);
                                var a = f.currentValueIndices;
                                var item = "";
                                if (typeof a == "number") {    // A single selection
                                  item = f.getItemAt(a, false);
                                }
                                else {     // Multiple selections
                                  item = f.getItemAt(a[0], false);
                                }
                              
                                f.setItems(aDropdownListData);
                              
                                // select the previously selected item again
                                for (var i in aDropdownListData) {
                                  if (aDropdownListData[i] == item) {
                                    f.currentValueIndices = [ i ];
                                  }
                                }
                              }
                              
                              

                              Now set this new field to read-only and hidden. This will take care of modifying the dropdown controls whenever you modify one of the text fields. It will also make sure that whatever setting was selected, will be selected again after this change (unless that value is no longer available).

                              1 person found this helpful
                              • 12. Re: Populating drop down lists
                                Acduffell Level 1

                                Awesome.  Works a treat now.

                                Thanks heaps