5 Replies Latest reply on Apr 5, 2016 2:29 PM by George_Johnson

    change the border color based off a dropdown selection

    MotoPsycho

      I've been looking and haven't quite found what I am looking for.  I have been tasked with working on a form.  Why?  I don't know.  I am a graphics and video guy so someone thinks because its a PDF I know what to do. 

       

      The form is used for several different personnel procedures and depending what it is used for some fields need to be filled out, and others don't.  What is being requested is that when an option is selected from a drop down menu (7 different options) that it would highlight (change the border color) of the fields that need to be filled out for that option. 

       

      I do understand that this is javascript and I do understand javascript, I just never had to do this in a PDF before.

       

      So from my ActionDrop  drop down menu you pick "New Hire" option all the fields that involve the new hire process are highlighted (change the border color from Black to Red), same goes for if you select "Separation" from the drop down.  Any help with this would be awesome.  Thanks

        • 1. Re: change the border color based off a dropdown selection
          George_Johnson MVP & Adobe Community Professional

          The programming could be simplified if you used hierarchical field naming for all of the fields you want to control. For example, instead of using fields names of "employee_name" and "address", added a prefix of something like "HL", so the field names get changed to "HL.employee_name" and "HL.address". If you do this, the custom Validate JavaScript for the dropdown could be something like:

           

          // Custom Validate script for dropdown

          (function () {

           

              // Initialize some variables

              var i, aFields = [], f_prefix = "HL";

           

              // Create an object to associate an array of field names with each dropdown item

              var oFields = {};

              oFields["item1"] = ["field1", "field2", "field5", "field8", "field9"];

              oFields["item2"] = ["field1", "field3", "field4", "field7", "field10"];

              oFields["item3"] = ["field1", "field4", "field11", "field12", "field13"];

              oFields["item4"] = ["field1", "field2", "field3", "field4", "field5"];

              oFields["item5"] = ["field2", "field4", "field6", "field8", "field10"];

              oFields["item6"] = ["field1", "field3", "field5", "field7", "field9"];

              oFields["item7"] = ["field3", "field4", "field5", "field6", "field7"];


              // Start be resetting all of the HL field's border color to black

              getField("HL").strokeColor = color.black;


              // Set the aFields array to the array of fields corresponding to the selected dropdown item

              aFields = oFields[event.value];


              // Loop through the fields in the array and set their border color to red

              for (i = 0; i < aFields.length; i += 1) {

                  getField(f_prefix + "." + aFields[i]).strokeColor = color.red;

              }


          })();




          This could be improved in a number of ways, but it should get you started. Change "item1", "item2", etc, with the actual dropdown values, and "field1", "field2", etc. in each array with the field names (without the "HL" prefix) corresponding to each dropdown item.


          • 2. Re: change the border color based off a dropdown selection
            George_Johnson MVP & Adobe Community Professional

            Note that I corrected a few typos in the code above, so be sure to use the updated code.

            • 3. Re: change the border color based off a dropdown selection
              MotoPsycho Level 1

              George -

               

              Thank you for the speedy reply.  Am I adding this code to the properties>actions of the drop down or into the format tab?  This javascript into a PDF is not making sense.  Thank you.

              • 4. Re: change the border color based off a dropdown selection
                George_Johnson MVP & Adobe Community Professional

                As I mentioned, it's a custom Validate script, so click on the Validate tab of the field properties dialog for the dropdown and you should see where to place the code.

                • 5. Re: change the border color based off a dropdown selection
                  George_Johnson MVP & Adobe Community Professional

                  By the way, a validate script that's attached to a field is automatically triggered whenever the field value changes, so it's a logical place for this type of script.

                   

                  A Format script is generally used to control what gets displayed in a field based on the actual value. For example, a value of 3.141592654 can be rounded to 3.14 for display, but the underlying value will remain the unrounded value.