13 Replies Latest reply on Mar 2, 2011 7:50 PM by maxwyss

    JavaScript using Color

    burlingtonnow Level 1

      I hope that I am not asking for to much.....but can Acrobat Pro Properties / Validation / Field value is in range, of 0-44,    change color  when this Field reaches 44. Is there a custom validation script that can change the color of the field or the number?

       

      Again thanks!!!

        • 1. Re: JavaScript using Color
          George_Johnson MVP & Adobe Community Professional

          If you want to use a Validation script, you would have to implement the range contraints there as well, as opposed to using the built-in option. How is the field in question getting populated? Is it set by some other field or calculation, or does the user entering the number manually?

          • 2. Re: JavaScript using Color
            maxwyss Level 4

            Although it can be done in the Validation event, changing field (display) properties without changing the value is preferrably done in the Format event.

             

            In either case, the script would look like this:

             

            if (event.value*1 < 44) {

            event.target.textColor = color.red ;

            } else {

            event.target.textColor = color.black ;

            }

             

            This would change the color of the text between black and red.

             

            HTH.

             

            Max Wyss.

            1 person found this helpful
            • 3. Re: JavaScript using Color
              burlingtonnow Level 1

              Hi George, Thanks for responding so quickly. Ok the field in question populates by a calculation from another field...ie it's the sum of todays date minus a inputed date. The field I want to change color is called 'Open' I want it to change green  range is from 0-44. then change yellow range 45-89 and last red from range 90 to 360. I hope this explains a little better.  Again Thanks George.

              • 4. Re: JavaScript using Color
                George_Johnson MVP & Adobe Community Professional

                OK, you just have to adapt Max's script to cover those ranges. If you get stuck, post what you've got.

                • 5. Re: JavaScript using Color
                  burlingtonnow Level 1

                  Okay I am stuck.... this is what I have. I also want the starting number which is 0 to be the color black. Right now it is starting out green.

                   

                  if (event.value*1 < 45) {
                  event.target.textColor = color.green ;
                  }
                  if (event.value*1 >46) {

                  event.target.textColor = color.yellow;
                  }
                  if (event.value*1 >365) {

                  event.target.textColor = color.red
                  } else {
                  event.target.textColor = color.black ;
                  }

                  • 6. Re: JavaScript using Color
                    burlingtonnow Level 1

                    I want the field to start out with a black 0.   The range is 1-45 to be green.  46-89 to be yellow and 90-365 to be red

                     

                    again this is what I have:  and it is not working.

                     

                      if (event.value*1 < 45) {
                    event.target.textColor = color.green ;
                    }
                    if (event.value*1 >46) {

                    event.target.textColor = color.yellow;
                    }
                    if (event.value*1 >365) {

                    event.target.textColor = color.red
                    } else {
                    event.target.textColor = color.black ;
                    }

                    • 7. Re: JavaScript using Color
                      try67 MVP & Adobe Community Professional

                      val = event.value*1;

                      if (val==0) {

                           event.target.textColor = color.black;

                      } else if (val<=45) {

                           event.target.textColor = color.green;

                      } else if (val<=89) {

                           event.target.textColor = color.yellow;

                      } else if (val>=90 && val<=365) {

                           event.target.textColor = color.red;

                      }

                      • 8. Re: JavaScript using Color
                        burlingtonnow Level 1

                        else if.......that what I was trying to remember

                         

                        if (event.value *1 < 44) {

                        event.target.textColor = color.green;

                        } else if (event.value*1 >45 && event.value*1 < 89) {

                        event.target.textColor = color. yellow;

                        } else if (event.value*1 >90 && event.value*1 < 365) {

                        event.target.textColor = color. red;

                        } else {

                        event.target.textColor = color. black;

                        }

                         

                        Can you tell me if this is right Please

                        • 9. Re: JavaScript using Color
                          try67 MVP & Adobe Community Professional

                          It will work, but it's not what you described in your post.

                          For example, if the value is 0 the text will be green and if it's 44 the text will be black.

                          Why not use my code from the previous post?

                          • 10. Re: JavaScript using Color
                            burlingtonnow Level 1

                            Thank You Try67

                            .

                            I was on the path but you put me on the correct path. Plus my next problem was to solve the val =event.value*1; if (val==0){

                             

                            I thank you.

                             

                            All the Best

                            • 11. Re: JavaScript using Color
                              maxwyss Level 4

                              You could think of this approach:

                               

                              if (event.value > 365) {

                              event.target.color = color.black ;

                              } else {

                              if (event.value > 90) {

                              event.target.color = color.red ;

                              } else {

                              if (event.value > 44) {

                              event.target.color = color.yellow ;

                              } else {

                              if (event.value > 0) {

                              event.target.color = color.green ;

                              } else {

                              event.target.color = color.black ;

                              }

                              }

                              }

                              }

                               

                               

                              It is a bit nested, but should actually work.

                               

                              HTH.

                               

                              Max Wyss.

                              • 12. Re: JavaScript using Color
                                gkaiseril MVP & Adobe Community Professional

                                I find the 'switch' statement is a little clearer to understand:

                                 

                                switch (true) {
                                case (event.value > 365):
                                   event.target.textColor = color.black;
                                break;
                                case (event.value > 90):
                                   event.target.textColor = color.red;
                                break;
                                case (event.value > 44):
                                   event.target.textColor = color.yellow;
                                break;
                                case (event.value > 0):
                                   event.target.textColor = color.green;
                                break;
                                default:
                                   event.target.textColor = color.black;
                                break;
                                } // end switch

                                • 13. Re: JavaScript using Color
                                  maxwyss Level 4

                                  Yep, a nice one, George.

                                   

                                  Max.