6 Replies Latest reply on Jan 19, 2017 2:06 AM by SteveK1982

    PDF JS Multiple Dropdowns, Multiple Function SetfieldValues

    SteveK1982 Level 1

      Hi all

       

      I have a quick query that hopefully someone can clear up with me. I have been creating a PDF document with dropdowns, and followed this guide which worked perfectly for me when populating other fields. My problem started when I wanted to add a second drop down, this dropdown contains the same content and needs to populate different fields in the same way as the first. The way I wrote the function for the second drop down is as follows. I know this is wrong because the functions have the same name but I do not understand scripting enough on how to name them differently, currently selecting a option from Dropdown1 will change the fields Duration2, Funding2 and Cont2.

       

      Dropdown 1 Keystroke Script

       

      if( event.willCommit )

      {

         if(event.value == " ")

           this.resetForm(["Duration1","Funding1","Cont1"]);

         else

           SetFieldValues(event.value);

      }

       

      Dropdown 2 Keystroke Script

       

      if( event.willCommit )

      {

         if(event.value == " ")

           this.resetForm(["Duration2","Funding2","Cont2"]);

         else

           SetFieldValues(event.value);

      }

       

      Document Script

      var

      Dropdown1Data = {Product A:{ Duration1: "6 Months",

                                    Funding1: "£100",

                                    Cont1: "£10" },

                                    Product B :{ Duration1: "12 Months",

                                    Funding1: "£200",

                                    Cont1: "£20" },;

                      

      Dropdown2Data = {Product A:{ Duration2: "6 Months",

                                    Funding2: "£100",

                                    Cont2: "£10" },

                                    Product B :{ Duration2: "12 Months",

                                    Funding2: "£200",

                                    Cont2: "£20" },;

       

      function SetFieldValues(cDropdown1)

      {

        this.getField("Duration1").value = Dropdown1Data[cDropdown1].Duration1;

        this.getField("Funding1").value = Dropdown1Data[cDropdown1].Funding1;

        this.getField("Cont1").value = Dropdown1Data[cDropdown1].Cont1;

      }

      function SetFieldValues(cDropdown2)

      {

        this.getField("Duration2").value = Dropdown2Data[cDropdown2].Duration2;

        this.getField("Funding2").value = Dropdown2Data[cDropdown2].Funding2;

        this.getField("Cont2").value = Dropdown2Data[cDropdown2].Cont2;

      }

       

      If you could help me work this one out it would be great, I have found other links that discuss the same issue, although I have not been smart enough to understand what to do now that I have the answer.

       

      Thanks

       

      Steve