4 Replies Latest reply on Feb 5, 2011 5:37 PM by AccessII

    Autofill dropdown from another dropdown - Allow Edit

    AccessII

      Hello experts!!

       

      I just started usind

      Adobe 10 Pro.

       

      I have 2 dropdowns both with all the same dropdown options (choices).  About 80% of the time the dropdown

      value in dropdown2 will be the same as in dropdown1, so I want to pre-populate dropdown2 with dropdown1 value but also allow the user to choose another value for dropdown2 if they need to. 

       

      I know that I can popluate dropdown2 from dropdown1 value with the following custom calculation script;

       

      event.value = this.getField("dropdown1").value

       

      This populates the feild just fine, but the user cannot choose a different value other than the one in dropdown1 if they need to.

       

      In my efforts to figure this out is see that a SWITCH command might be helpful, but I don't know how to use the command correctly, or if that is the best way to go.

      Any help is GREATLY appreciated!!
        • 1. Re: Autofill dropdown from another dropdown - Allow Edit
          George_Johnson MVP & Adobe Community Professional

          It would probably be better to set the second combo box value with a Validate or Keystroke script (depending on how it's set up) in the first combo box, but you need to provide more information about how you want it to work.

           

          For example, what should happen if the user chooses an item in combo1 (thus setting combo 2 to the same), chooses a different item in combo2, and then goes back and chooses a different item in combo1? Should it then set combo2 to the same again?

          • 2. Re: Autofill dropdown from another dropdown - Allow Edit
            AccessII Level 1

            George,

             

            The short answer to your question is NO.

             

            If the user chooses a new value in Dropdown2, then goes back to Dropdown1 and changes it, the value in Dropdown2 would not change back to the Dropdown1 value.

             

            Thanks,

            Dan

            • 3. Re: Autofill dropdown from another dropdown - Allow Edit
              George_Johnson MVP & Adobe Community Professional

              I was afraid you'd say that, because it complicates things a bit. You have to have some way of indicating that the user made a selection in the second combo box. You can use a document-global variable for this. To set it up, add a new document-level javaScript (Advanced > Document Processing > Document JavaScripts) that is the following:

               

              // Flag indicating whether the user changed the value of combo box 2

              var cb2_changed = false;

               

              Make sure this code is outside of a function definition. You can call the document-level JavaScript whatever you want (e.g., "init") and delete the function skeleton it provides you by default.

               

              Next, add the following custom Keystroke script for the first combo box:

               

              // Custom Keystroke script for combo box 1
              if (!event.willCommit) {

               

                  // Get the value the user selected
                  var val = event.changeEx;

               

                  // Get a reference to the other combo box
                  var f2 = getField("cb2");

               

                  // Only set the value of combo box 2
                  // if it has not been changed by the user
                  if (!cb2_changed) {
                      f2.value = val;
                  }
              }

               

              Change "cb2" to the actual name of the second combo box.

               

              Finally, add the following as the custom Keystroke script for the second combo box:

               

              // Custom Keystroke script for combo box 2
              if (!event.willCommit) {

               

                  // Get the value the user selected
                   var val = event.changeEx;

               

                  // Get the current value of this field
                  var prev_val = event.target.value;

               

                  // Set flag indicating the user selected a new value
                  if (val != prev_val) {
                      cb2_changed = true;
                  }
              }

               

              This code assumes the combo box items have export values and that they're identical for combo box 1 and 2. Also, select the "Commit selected value immediately" option for both combo boxes. You can create a general document-level function based on this code so it can be reused by any number of combo box pairs that you want to behave this way. Post again if you get stuck.

              • 4. Re: Autofill dropdown from another dropdown - Allow Edit
                AccessII Level 1

                George,

                 

                PERFECT!!  Your code and instructions were right on the money.  Works lick a charm!

                 

                I really appreciate you and your willingness to help!!

                 

                Dan