10 Replies Latest reply on May 24, 2011 6:56 AM by santropez1971

    Populate another dropdown based on first

    StewyT Level 1

      What I want to do is to have 2 dropdowns.

       

      For example the first dropdown would have "Male" and "Female" and the second dropdown would populate either a list of female or male names depending on what was selected from the first dropdown. I don't want to deal with having the dropdown pull data from another source. I just want it to all be in the .pdf (if that makes sense?)

       

      I have searched and searched to try and figure out how to do this, and while I have found some close examples, I have not been able to figure them out how to modify them to be able to make them work for my needs. Any help/examples would be greatly appreciated!


      T.

        • 1. Re: Populate another dropdown based on first
          Worsty2 Level 1

          I don't know if you want to take this approach but what I did on my form where I had a dropdown with 2 values:  Value1, Value2.  I created 2 dropdown boxes that contained the values I wanted for Value1 and values for Value2.  I hid both of the dropdowns (Value1 and Value2 dropdowns).  When you made the selection you wanted from the first dropdown with the Values of Value1 and Value2, then the appropriate dropdown box would appear and a selection could be made.  I placed these dropdowns right on top of each other so you can't tell that there are two of them.

           

           

          Debbie

           

          "Life is half spent before we know what it is."

           

          George Herbert

          1 person found this helpful
          • 2. Re: Populate another dropdown based on first
            pguerett Level 6

            Thats one way to do it it you coudl write code n the exit event that woudl populate the 2nd ddlist based on the value chosen in the 1st list. Assuming the list with Gender is DDlist1 and the names is DDlist2 the javascript code would be placed on the exit event of the DDlist1 object and woud look something

            like this:

            //Cleanup the DDlist2

            DDlist2.rawValue = "";

            DDlist2.clearItems();

             

            //User selected Male from the list

            if (this.rawValue == "Male"){

                 DDlisr2.addItem("Frank")

                 DDlist2.addItem("Bob")

                 add one statement for each name

            }  else {

                 //Only two choices so the other choice must be selected

                 DDlist2.addItem("Rachael");

                 DDlist2.addItem("Julie");

                 add one statement for each name

            }

             

            Hope that helps

            Paul

            1 person found this helpful
            • 3. Re: Populate another dropdown based on first
              StewyT Level 1

              Both solutions make sense, but re: the first option, I'm not sure how to "unhide" the second dropdown once something from the first dropdown is selected and the 2nd solution doesn't work (I did catch the typo in the code, but still no luck). Not sure what I am doing wrong. Also I'd really like to have more than 2 items to select from in the 1st dropdown, so I am not sure if some type of if/then code would even work? I want to have 4 options to select from. Thanks.

              • 4. Re: Populate another dropdown based on first
                StewyT Level 1

                Managed to finally figure out a way to get this to work basing the code off of some code I found on how to have a dropdown selection fill in text fields. Thought I would share my solution, so I have pasted the code below. Can't wait to get my form completed and start using it. It's going to save me so much time by not having to enter the same information over and over and over. Thanks for your help, it helped steer me in the right direction to finding the solution I needed.

                 

                ----- form1.#subform[0].DropDownList1::change: - (JavaScript, client) ------------------------------

                 

                DropDownList2.clearItems();

                 

                var sNewSel = this.boundItem(xfa.event.newText);

                 

                switch (sNewSel)

                 

                {

                 

                  case "Doctor 1":

                 

                    DropDownList2.addItem("BCBS")
                    DropDownList2.addItem("Aetna")
                    DropDownList2.addItem("Cigna")
                    DropDownList2.addItem("UHC")

                 

                    break;

                 

                  case "Doctor 2":

                 

                    DropDownList2.addItem("BCBS")
                    DropDownList2.addItem("Aetna")
                    DropDownList2.addItem("Cigna")
                    DropDownList2.addItem("UHC")

                 

                    break;
                   
                  case "Doctor 3":

                 

                    DropDownList2.addItem("BCBS")
                    DropDownList2.addItem("Aetna")
                    DropDownList2.addItem("Cigna")
                    DropDownList2.addItem("UHC")

                 

                    break;

                 

                  case "Doctor 4":

                 

                    DropDownList2.addItem("BCBS")
                    DropDownList2.addItem("Aetna")
                    DropDownList2.addItem("Cigna")
                    DropDownList2.addItem("UHC")

                 

                    break;
                   
                  default:

                 

                    break;

                 

                }

                • 5. Re: Populate another dropdown based on first
                  santropez1971 Level 1

                  I'm trying to accomplish the same task but with no success.

                   

                  I'm using Acrobat Pro X

                   

                  I have a dropdown called "Assay" which has three entries that users can pick (Assay 1, Assay 2, Assay 3).

                   

                  I have a second drowndown called "Description" who's contents should vary based on what's choosen in the first dropdown.

                   

                  I used the code from the last post and modified it but it does not seem to work, the Description dropdown is not getting updated. I added the code to the Dropdown Properties menu using the trigger Mouse Up (I also tried Mouse Exit with no luck).

                   

                  My code starts here:

                   

                  Description.clearItems();

                   

                  var sNewSel = this.boundItem(xfa.event.newText);

                   

                  switch (sNewSel)

                   

                  {

                   

                    case "Assay 1":

                   

                      Description.addItem("BCBS")

                      Description.addItem("Aetna")

                      Description.addItem("Cigna")

                      Description.addItem("UHC")

                   

                      break;

                   

                    case "Assay 2":

                   

                      Description.addItem("BCBS")

                      Description.addItem("Aetna")

                      Description.addItem("Cigna")

                      Description.addItem("UHC")

                   

                      break;

                   

                    case "Assay 3":

                   

                      Description.addItem("BCBS")

                      Description.addItem("Aetna")

                      Description.addItem("Cigna")

                      Description.addItem("UHC")

                   

                      break;

                   

                    default:

                   

                      break;

                   

                  }

                  • 6. Re: Populate another dropdown based on first
                    pguerett Level 6

                    Your code looks fine but the xfa.event.newText is not populated on those events. You should move your code to the Change  event.

                     

                    Paul

                    • 7. Re: Populate another dropdown based on first
                      santropez1971 Level 1

                      Paul,

                       

                      Thanks for your response, forgive me for being a noob here.

                       

                      After a little googling, are you suggesting i use xfa.event.change in place of the xfa.event.newText? If so, I just tried that and no go, the second list still does not change at all.

                       

                      My new code after your suggestion:

                       

                      DescriptionList.clearItems();

                       

                      var sNewSel = this.boundItem(xfa.event.change);

                       

                      switch (sNewSel)

                       

                      {

                       

                        case "Assay 1":

                       

                          DescriptionList.addItem("BCBS")

                          DescriptionList.addItem("Aetna")

                          DescriptionList.addItem("Cigna")

                          DescriptionList.addItem("UHC")

                       

                          break;

                       

                        case "Assay 2":

                       

                          DescriptionList.addItem("BCBS")

                          DescriptionList.addItem("Aetna")

                          DescriptionList.addItem("Cigna")

                          DescriptionList.addItem("UHC")

                       

                          break;

                       

                        case "Assay 3":

                       

                          DescriptionList.addItem("BCBS")

                          DescriptionList.addItem("Aetna")

                          DescriptionList.addItem("Cigna")

                          DescriptionList.addItem("UHC")

                       

                          break;

                       

                        default:

                       

                          break;

                       

                      }

                      • 8. Re: Populate another dropdown based on first
                        pguerett Level 6

                        No ....there is nothing wrong with the code that I can see .....I mean cut the cude from the current ebent that you are on and paste it on the change event of the DDList.

                         

                        Paul

                        • 9. Re: Populate another dropdown based on first
                          santropez1971 Level 1

                          Okay, getting closer now. I changed my code back now that I understand what you are saying I just can't find a change as you are describing. I had been using the Actions tab, on a Mouse Up trigger. I removed that and tried to add it on the Validate tab, running a custom validation script, didn't seem to work either. Going to look further to see where exactly where I paste in the code for a change event as you suggest.

                           

                          Also, on StewyT's post above, his code has this at the top:

                           

                          ----- form1.#subform[0].DropDownList1::change: - (JavaScript, client) ------------------------------

                           

                          I don't need that in my code do I? When I add that line, the Javascrpt editor/save throws an error. Again, forgive me as this is new territory for me, javascript and all.

                          • 10. Re: Populate another dropdown based on first
                            santropez1971 Level 1

                            Okay gang, I finally got this working.

                             

                            They key was to not try and do this in Acrobat, but do this in LiveCycle designer. I had assumed that LiveCyle was a separate product and didn't realize it installed with my Acrobat Pro license. It was much easier to get working with many more options vs Acrobat X.

                             

                            Good luck

                             

                            Here is the final code I used. This was added on the "change" event within the properties of my first DDList within LiveCycle Designer.

                             

                            Description.rawValue = "";

                            Description.clearItems();

                             

                            var sNewSel = this.boundItem(xfa.event.newText);

                             

                            switch (sNewSel)

                             

                            {

                             

                              case "Assay 1":

                             

                                Description.addItem("Assay 1: Description 1")

                                Description.addItem("Assay 1: Description 2")

                                Description.addItem("Assay 1: Description 3")

                                Description.addItem("Assay 1: Description 4")

                             

                                break;

                             

                              case "Assay 2":

                             

                                Description.addItem("Assay 2: Description 1")

                                Description.addItem("Assay 2: Description 2")

                                Description.addItem("Assay 2: Description 3")

                                Description.addItem("Assay 2: Description 4")

                             

                                break;

                             

                              case "Assay 3":

                             

                                Description.addItem("Assay 3: Description 1")

                                Description.addItem("Assay 3: Description 2")

                                Description.addItem("Assay 3: Description 3")

                                Description.addItem("Assay 3: Description 4")

                             

                                break;

                             

                              default:

                             

                                break;

                             

                            }