9 Replies Latest reply on Jul 24, 2014 2:18 PM by kcaero

    Changing text field border color based on a dropdown value

    kcaero Level 1

      I have a Dropdown menu with 4 choices of maintenance priority.  With a javascript, I need to be able to select a "Priority" from a dropdown and then color a textbox border with an appropriate color.

       

      "High Priority"                  with an Export Value of  0

      "Medium Priority"             with an Export Value of  1

      "Low Priority"                   with an Export Value of  2

      "When Time Permits"      with an Export Value of  3

       

      When one of these selections has been made, a text box becomes available in order to write the discrepancy. My Goal is this.

       

      When "High Priority" is selected, the border around the text box where you would write the discrepancy would turn red.

      When "Medium Priority" is selected, the border around the text box where you would write the discrepancy would turn yellow.

      When "Low Priority" is selected, the border around the text box where you would write the discrepancy would turn green.

      When "When Time Permits" is selected, the border around the text box where you would write the discrepancy would turn blue.

       

      Otherwise the border would be white.

       

      This form will ultimately be used on an iPad using PDF Expert as the reader.     I am using Acrobat X to create the form.

       

      Any help would be appreciated. 

        • 1. Re: Changing text field border color based on a dropdown value
          George_Johnson MVP & Adobe Community Professional

          You say "Otherwise the border color would be white." Are there other possible selections in the dropdown that you haven't mentioned?

          • 2. Re: Changing text field border color based on a dropdown value
            kcaero Level 1

            The white border will be a default value with a empty dropdown selection, when the form is cleared there will be no border shown.

             

            Sent from my iPad

            • 3. Re: Changing text field border color based on a dropdown value
              George_Johnson MVP & Adobe Community Professional

              There has to be one item selected, but it can be an item that consists of just a single space so it appears to be blank. Have you have any script in place, or do you need to start form scratch?

              • 4. Re: Changing text field border color based on a dropdown value
                kcaero Level 1

                Hi George,

                 

                I do already have the blank in the dropdown without a problem.  I really need to start from scratch on a javascript.  I can't seem to get a script to do anything close to what I am looking for. 

                 

                Thanks again,   Ken

                • 5. Re: Changing text field border color based on a dropdown value
                  kcaero Level 1

                  Hi again George,

                   

                  Ive have been on a trip and not been able to work on this for a few days.....but now ready to start working on this once again.

                   

                  I have been trying to get this script to work, however it only will work on the last selection and turn the border blue. 

                   

                  This is placed in the source dropdown field in the validate dropdown property box.

                   

                   

                  // Validatescript of dropdown

                  (function ()

                   

                  {

                  // Get areference to the other dropdown

                  var f =getField("discrepancy 1");

                   

                   

                  // Set its background color based on thisdropdown's value

                      f.borderColor = event.value === "0"? color.red : color.white;

                      f.borderColor = event.value === “1" ?color.yellow : color.white;

                      f.borderColor = event.value === “2" ?color.green : color.white;

                      f.borderColor = event.value === “3" ?color.blue : color.white;

                   

                   

                  })();

                   

                   

                  any guidance or suggestions?

                  • 6. Re: Changing text field border color based on a dropdown value
                    George_Johnson MVP & Adobe Community Professional

                    Try this as the custom Keystroke script for the dropdown:

                     

                    // Custom Keystroke script for dropdown

                    (function () {

                     

                        if (!event.willCommit) {

                            exp_val = event.changeEx;

                     

                            // Get a reference to the text field

                            var f = getField("discrepancy 1");

                     

                            // Set the stroke color of the text field based on the dropdown selection

                            switch (exp_val) {

                            case "0" :

                                f.strokeColor = color.red;

                                break;

                            case "1" :

                                f.strokeColor = color.yellow;

                                break;

                            case "2" :

                                f.strokeColor = color.green;

                                break;

                            case "3" :

                                f.strokeColor = color.blue;

                                break;

                            default :

                                f.strokeColor = color.white;

                                break;

                            }

                        }

                     

                    })();

                     

                     

                    Remove your validation script and also set the "Commit selected value immediately" option for the dropdown. This should work with PDF Expert, but be sure to test it. Note that the borderColor field property was depricated long ago, so you shouldn't use it even though it's still available, even in PDF Expert.

                    • 7. Re: Changing text field border color based on a dropdown value
                      kcaero Level 1

                      This works awesome George.  I  did receive a syntax error at line 56 which showed      })();  in error.       I modified the syntax to     }})();   and everything worked fine.

                       

                      When I reset the form however, the default white border does not appear.  The last selected color remains.  I did check that I have "Commit selected value immediately" and it is.  It will only default white if I purposely click on the blank dropdown space.  I have the reset button properties under Action to show "Reset Form"...... "priority1" dropdown selected for reset and the blank space in the dropdown as a default.  Any suggestions?

                       

                       

                      Thank you on the borderColor vs strokeColor field property information.....I will make that a habit from here out.

                       

                       

                       

                      I really appreciate your help!

                      • 8. Re: Changing text field border color based on a dropdown value
                        George_Johnson MVP & Adobe Community Professional

                        Yes, I accidentally left off a curly brace. I'll fix that so it won't be a problem if someone else tries to use it. Glad you got it working.

                         

                        To handle the reset, you can use a validate script for the dropdown:

                         

                        // Validate script for dropdown

                        if (event.value === " ") {

                            getField("discrepancy 1").strokeColor = color.white;

                        }

                        • 9. Re: Changing text field border color based on a dropdown value
                          kcaero Level 1

                          Perfect George!!  Thank you ever so much.  

                           

                          I'm sure I will have more questions to follow.  I start working on another form tomorrow.