12 Replies Latest reply on Dec 8, 2015 1:18 PM by allM48966999

    Scripting two Drop Down Menus

    kodiem13114922

      Hello everyone,

       

      I am currently building a form in Acrobat XI pro. The form is rather simple. The form consists of two drop down menus and several text boxes. The text boxes are pre-filled based on a selection from the drop down menu(s). My issue is because of form design is slim and long meaning I am stacking my text boxes and Drop Down Menus. So to give an example

       

      drop 1

      text 1

      text 2

      text 3

      text 4

      text 5

      text 6

      text 7

      text 8

      drop 2

      text 9

      text 10

      text 11

       

      The reasons there is so many text boxes in between the drop down menus is the "case" will use 3-8 of the texts boxes. My question is can I have drop down menu 2 populate any of the text boxes above it depending on the "case" selected in drop down menu 1.

       

      So for example drop down menu 1 has an option labeled "Standard Protection Package #1" . This option pre-populates text fields 1, 2 , and 3

       

      Now if in drop down menu 2 I selected "Full Vehicle Window Tint" I want it to populate text box 5

       

      but if in drop down menu 1 option "Standard Protection Package #1" it takes pre-populates text box 1,2,3 & 4

       

      If I selected the same option in Drop Down menu 2 I would want it to pre-populate text box 7

       

      I hope this makes since

       

       

      Thanks in advance,

      Nick

        • 1. Re: Scripting two Drop Down Menus
          try67 MVP & Adobe Community Professional

          You didn't really specify with what you want to populate the fields, but one approach would be to use something like this as the custom calculation script of your text field:

           

          var v1 = this.getField("Dropdown1").value;
          var v2 = this.getField("Dropdown2").value;
          if (v1=="Standard Protection Package #1" && v2=="Full Vehicle Window Tint") event.value = "Something";
          if (v1=="Standard Protection Package #1" && v2=="Something Else") event.value = "Some other text";
          if (v1=="Standard Protection Package #2" && v2=="Full Vehicle Window Tint") event.value = "Something #2";
          if (v1=="Standard Protection Package #2" && v2=="Something Else") event.value = "Some other text #2";
          // etc.
          
          • 2. Re: Scripting two Drop Down Menus
            kodiem13114922 Level 1

            try67,

             

            thanks for the response. Here is a copy of the java I have under one of the drop down menus already t "prepopulate" based off of selection. This is drop down menu 2 (name of field is  "optional"  in acrobat).

             

            var sNewSel = event.value;
                 switch (sNewSel) {
            case "Full Vehicle Window Tint":
                     this.getField("op2").value = "Driver, Passenger, Rear Passenger, & Rear Window";
               this.getField("opprice").value = "$265.00";
                     break;

              
            case "Vehicle Front Window Tint":
                     this.getField("op2").value = "Vehicles Driver & Passenger Window";
               this.getField("opprice").value = "$100.00";
                     break;

            case "Coupe Window Tint Full":
                     this.getField("op2").value = "Vehicles Driver, Passenger & Rear Window Tinted";
               this.getField("opprice").value = "$165.00";
                     break;

            case "CilaJet":
                     this.getField("op2").value = "Interior & Exterior Vehicle Protectant";
               this.getField("opprice").value = "$795.00";
                     break;
             
             
                case " ":
                    this.getField("optionaltxt").value = " ";
              this.getField("opprice").value = " ";
              this.getField("op2").value = " ";
                    break;
            //etc.
                 }

             

            Basically what I am trying to do is if Standard Protection Package #1 is chosen from drop down menu 1 (name is "Package" acrobat) then if I choose "Full Vehicle Window Tint" in drop box 2 it will populate text field 5, but if Standard Protection Package #2 is chosen with the same option chosen in drop down menu 2 it pre-populates text field 7 with the description found above under "Full Vehicle Window Tint" case..

             

            Does this help?

            • 3. Re: Scripting two Drop Down Menus
              try67 MVP & Adobe Community Professional

              The code I provided will do that... You just need to adjust the values of the drop-downs and the values you want to assign in the text field.

              • 4. Re: Scripting two Drop Down Menus
                kodiem13114922 Level 1

                Where would I place this code?

                • 5. Re: Scripting two Drop Down Menus
                  try67 MVP & Adobe Community Professional

                  As I wrote, as the custom calculation script of your text field.

                  • 6. Re: Scripting two Drop Down Menus
                    kodiem13114922 Level 1

                    thank you very much it works great :-)

                    • 7. Re: Scripting two Drop Down Menus
                      allM48966999

                      kodiem13114922 Please mark the question as answered if you are satisfied with the answer. Thanks.

                       

                      try67 I am trying to figure out a similar thing but cant get it to go. Here is my JS.

                      My selection field type is a dropdown menu. The fields I want populated are text type. Is adobe scanning the document for the names i gave to my text fields and then applying the value? I assumed as much in naming them but it is not working. Is there some documentation on this somewhere? (new to Adobe Forms) Thank you. Link to the form on my google drive is here.

                       

                      var choosePlan = event.value;

                      switch (choosePlan) {

                        case "Klik Social50":

                          this.getField("baseMonthlyPrice").value = "$500";

                          this.getField("threeMonths").value = "$1500";

                          this.getField("tca").value = "$150";

                          this.getField("totalPayment").value = "$1650";

                          break;

                        case "Klik Social100":

                        this.getField("baseMonthlyPrice").value = "$750";

                          this.getField("threeMonths").value = "$2250";

                          this.getField("tca").value = "$225";

                          this.getField("totalPayment").value = "$2475";

                          break;

                        case "Klik Social+SEO":

                        this.getField("baseMonthlyPrice").value = "$1700";

                          this.getField("threeMonths").value = "$5100";

                          this.getField("tca").value = "$510";

                          this.getField("totalPayment").value = "5610";

                          break;

                        case "Klik Entreprise":

                        this.getField("baseMonthlyPrice").value = "$2400";

                          this.getField("threeMonths").value = "$7200";

                          this.getField("tca").value = "$720";

                          this.getField("totalPayment").value = "7920";

                          break;

                      }

                      • 8. Re: Scripting two Drop Down Menus
                        try67 MVP & Adobe Community Professional

                        Not sure what you mean by "Is adobe scanning the document for the names i gave to my text fields and then applying the value?"... It looks up the field name you've specified as the parameter for getField. If no field with that name is found that method returns null.

                         

                        I've tried to look at your file but you need to grant me access to do so...

                        • 9. Re: Scripting two Drop Down Menus
                          try67 MVP & Adobe Community Professional

                          Move the code to the field's custom Validation event, instead of the

                          MouseUp event.

                           

                          On Tue, Dec 8, 2015 at 8:03 PM, allM48966999 <forums_noreply@adobe.com>

                          • 10. Re: Scripting two Drop Down Menus
                            allM48966999 Level 1

                            @try67 you are the man. That worked. Is in the docs somewhere? I cant seem to find it. Thank you for the guidance. Do you do this for fun or can I plug your consulting services somewhere?

                            • 11. Re: Scripting two Drop Down Menus
                              try67 MVP & Adobe Community Professional

                              It's documented to some extent in the Acrobat JS API Reference, but it's more the product of a lot of experience with these kinds of scripts.

                               

                              I develop custom-made tools for PDF files (and other things) for a living, so it would be nice if you could drop a nice word on my web-site, for example:

                              Custom-made Adobe Scripts: Clients Feedback

                              • 12. Re: Scripting two Drop Down Menus
                                allM48966999 Level 1

                                Done under my own name. Was logged in on someone else's account here.

                                Thank you, sir.