Change Fill Color Based On Value | Community
Skip to main content
April 2, 2010
Solved

Change Fill Color Based On Value

  • April 2, 2010
  • 13 replies
  • 19595 views

I have found several good examples on how to modify the color of a field based on a value but am not having luck implementing.  My form is an evaluation with 3 sections of test scores, the total of all 3 could have a max value of 100.  Sections 1 & 2 are auto calculated, and section 3 is a value the user will input based on their review of all comments, scores, etc.  The final score has a rating, Outstanding 90-100, Satisfactory 70 - 89, and Unsatisfactory <=70.   Right now I'm not so much concerned about the color numbers, but I'm not able to get the colors to change at all.  Because this field is calculated based on sections 1-3, I put the code on its change event.  Once the user enters the final manual score in section 3, the value automatically changes.  I've also tried the exit event of the section 3 manual score, and obviously do not have either the code or where to place it right.  Below is the code I'm using, and would appreciate any help.  If I can learn how to do the 90-100, hopefully I can apply same method, different color to 70-89 and under 70.  What am I doing wrong?  Thank you.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Kevin_Cavallo

I have an example for you, but it looks like uploading has been disabled again.  Send me a direct email with your email address and I'll send you the document.

13 replies

New Participant
April 2, 2010

It's a little hard to tell exactly what's happening without seeing your form. If you want manual input on one field to change the color of a second field after recalculation, the color change should probably go in the calculate event of the field you want to change, after the calculation is complete.

One thing to check is to make sure you're previewing your form as a dynamic form.  In the File menu, select Form Properties and on the Preview tab make sure the Preview Adobe Form As: selection is set to Dynamic XML Form.

April 2, 2010

Thank you.  I moved the code to the exit event of the field requiring manual input, and it's still not changing.  I was wondering if it was because the field I want to color-code doesn't calculate till the manual input field is exited, so I tried it again on the change event of the desired color-coded field, but still not working yet.  I don't know the colors yet and thought it might be that I'm choosing the wrong numbers, and found a good link and example here (http://www.acrobatusers.com/tutorials/using-colors-acrobat-javascript) to help me with the colors, and will get the numbers worked out for each condition, but for some reason I'm not getting any results yet on even the basic first step, thanks.

New Participant
April 2, 2010

You're on the right track, but the javascript syntax is a little off.  Here's how it should look:

if ( this.rawValue <= 100 &&this.rawValue >= 90 )

     {

    this.fillColor = "102,179,255";

     }

You need parenthesis around the entire "if" statement, and a semicolon at the end of the fillcolor statement.

Also, you might want to put the code in the "exit" event rather than the "change" event.  With change, the event will fire every time a character is typed.  The exit event will fire when the user is done entering text and clicks off of the field.  This way, the code only evaluates the entered number when it is complete.