Expand my Community achievements bar.

Join us in celebrating the outstanding achievement of our AEM Community Member of the Year!

Javascript to change fill color based on dropdown input

Avatar

Level 1

First, let me start by saying that I am a 1,000,000% novice.  I merely type my question in google and spend a ridiculous amount of time looking and praying for scripts that I can cut, paste and modify it see if they work.  Most of the time, I have no idea how it works and I don't really care as long as it works.  So, with that said, here's my issue.  I have an Adobe Acrobat Pro XI form (NOT LiveCycle) that I created.  I have dropdown fields with values of Exceeds (blue), Meets (green), Needs Improvement (yellow) and Does Not Meet (red).  When the user selects the applicable value, I need the field to change to the color.  The script below was working fine UNTIL I got overzealous and thought I could change blue and green to shades that I preferred.  Now, even though I've removed my RGB definitions of those colors, if I select Exceeds or Meets, the fill color is Aqua.  It's as though I've 'broken' the defaults and it's being held in memory.  Here is the script I'm using.  Again, I copied this script somewhere off the web, so please be kind

if (event.value=="Exceeds") event.target.fillColor = color.blue;

else if (event.value=="Meets") event.target.fillColor = color.green;

else if (event.value=="Needs Improvement") event.target.fillColor = color.yellow;

else if (event.value=="Does Not Meet") event.target.fillColor = color.red;

else event.target.fillColor = color.white;

Here is the script I used when I tried to redefine the colors:

color.blue= ["RGB", 0,112,192];

color.green= ["RGB", 0,176,80];

if (event.value=="Exceeds") event.target.fillColor = color.blue;

else if (event.value=="Meets") event.target.fillColor = color.green;

else if (event.value=="Needs Improvement") event.target.fillColor = color.yellow;

else if (event.value=="Does Not Meet") event.target.fillColor = color.red;

else event.target.fillColor = color.white;

How do I get Exceeds and Meets back to blue and green and how can I define what shades of blue and green I want?

Thanks!

2 Replies

Avatar

Level 1

I managed to return the default blue and green colors.  Now, I just need to know how to define different shades of blue and green, the standard RGB codes don't appear to be working or is my syntax incorrect.  I really need to get the form completed by tomorrow.  I can live with the green shade, but the blue is too dark for the black text to show up well.  Anybody??

Avatar

Level 1

Well, I guess it's like I tell my daughter..."you're resourceful, you'll figure it out".  I learned that javascript doesn't recognize the standard 0-255 color codes and that you have to divide the numbers...So my new script worked perfectly.  I'm so proud of myself! .  Now on to more challenges!

color.new_blue = ["RGB", 0, 100/255, 200/255];
color.new_green = ["RGB", 0, 176/255, 80/255]
if (event.value=="Exceeds") event.target.fillColor = color.new_blue;

else if (event.value=="Meets") event.target.fillColor = color.new_green;

else if (event.value=="Needs Improvement") event.target.fillColor = color.yellow;

else if (event.value=="Does Not Meet") event.target.fillColor = color.red;

else event.target.fillColor = color.white;