5 Replies Latest reply on Oct 18, 2010 1:43 PM by Thom Parker

    Combo box dilemma ~ $$$


      Adobe Scripters,


      Looking for a script i can add to the Combo Box properties>Actions>Run a JavaScript on 3 different Combo Boxes.


      Basically i need the following code created.


      If Combobox1 option item1 selected textfield1 = 123456

      textfield2 = 987654

      textfield3 = 523452


      If Combobox1 option item2 selected textfield1 = abcde

      textfield2 = qwerty

      textfield3 = asdfg


      If Combobox2 option item1 selected textfield4 = 123456

      textfield5 = 987654

      textfield6 = 523452


      If Combobox2 option item2 selected textfield4 = abcde

      textfield5 = qwerty

      textfield6 = asdfg


      If Combobox3 option item1 selected textfield4 = 1q1w2e3

      textfield5 = w2e3r4t5

      textfield6 = q1w2e3r4


      If Combobox3 option item2 selected textfield4 = p09i8u7

      textfield5 = p0o9i8u7

      textfield6 = p0o9i8u7


      I only need one script that i could use in each of the "Combo Box properties>Actions>Run a JavaScript".






        • 1. Re: Combo box dilemma ~ $$$
          Scott C Clark Level 1

          Look into the switch case statement in javascript.


          var combo1 = this.getField("Combo Box12").value;
          var endDefault;

          var a = this.getField("Text6.0.0")

          switch (combo1){

          case "Select a product":
          a.display = display.hidden;


          case "Product One":
          a.display = display.visible,
          getField("Text6.0.0").value = "P1";


          case "Product Two":
          a.display = display.visible,
          getField("Text6.0.0").value = "P2";


          case "Product Three":
          a.display = display.visible,
          getField("Text6.0.0").value = "P3";

          endDefault = false;

          if (endDefault = false)
          app.alert("Please select from the drop-down menu",3);

          1 person found this helpful
          • 2. Re: Combo box dilemma ~ $$$
            gkaiseril MVP & Adobe Community Professional

            See Changing Another Field with Combo Box (Drop Down) Selection by Thom Parker, You only need to maintain the data object and combo box when changing the available choices and no code. It is even possible to load the combo box from the data object so one only needs to maintain the data object.

            1 person found this helpful
            • 3. Re: Combo box dilemma ~ $$$
              sthompson86 Level 1

              Thanks for the advice GKaiseril but my problem is i need to use 3 main fields that set the field values. Im already using this script and it allows me to have one combo box control 5+ text fields, But when i need to be able to use this script 3 times within the page. For some reason this script wont allow me to choose what the main combo box is that is used to change autofill the other text/combo boxes.

              • 4. Re: Combo box dilemma ~ $$$
                gkaiseril MVP & Adobe Community Professional

                You may need to write some additional functions to perform the set for the other fields.

                • 5. Re: Combo box dilemma ~ $$$
                  Thom Parker Adobe Community Professional

                  Yes, you'll need to add some additional code to generalize the function to be used with any combobox.  The issue is that each combobox affects different fields, and has a different source for the data that is placed in those fields.  So it's a matter of abstraction, the code needs to abstract both the names of the affected fields and the data that is placed in those fields.


                  One way to do this is to create a data table (object) for each combobox that includes both the names of the fields and the data that is used for those fields. Then this object is passed into the  "SetFields" function for each combobox.  So the change event on the combobox would include code that looks like this:




                  The easiest way to deal with different field names is to use the same name for both the form field that's being set, and the data field that it is set from.  For example, in the article the sample data looks like this.



                  var DeptData = { Accounting:{  contact: "Steala Damuni",
                                                 email: "accounting@mycomp.com",
                                                 deptnum: "cmp1234" },
                                   Engineering:{ contact: "Frank N. Stien",
                                                 email: "engineering@mycomp.com",
                                                 deptnum: "eng1234" },
                                   Marketing :{  contact: "Shelly Oughtbuks",
                                                 email: "marketing@mycomp.com",
                                                 deptnum: "mkt1234" },
                                   ITSupport:{   contact: "Goah  Wei",
                                                 email: "it@mycomp.com",
                                                 deptnum: "its1234" }};




                  Where each entry in the combobox returns an object with 3 elements, "contact", "email", and "department".  If the fields have the same name then the code can be written to simple use the name of the entries as the field names.  Like this:


                  function SetFields(oDataObject)


                    var oValues = oDataObject[event.value];


                    for(var cFld in oValues)

                        this.getField(cFld).value = oValues[cFld];



                  Now everything is controlled from the data object that's used for the combobox and the SetFields function can be used with any control, as long as there is a corresponding data object.


                  Thom Parker
                  The source for PDF Scripting Info


                  The Acrobat JavaScript Reference, Use it Early and Often


                  Then most important JavaScript Development tool in Acrobat
                  The Console Window (Video tutorial)
                  The Console Window(article)