Copy link to clipboard
Copied
I am trying to have the background fill color and font color change dependant on the value in a PULL-DOWN menu and once the color changes ...to remain at the newly coded color. I am using a text field in a PDF file accessed with Adobe Acrobat.
Peter
Copy link to clipboard
Copied
What have you tried so far, and what were the results?
Copy link to clipboard
Copied
Thanks for the quick reply.
I am new to coding in Acrobat and really don't have a clue.
What I am trying to do is the following:
Thank you...
Peter
Copy link to clipboard
Copied
OK. First of all, the "grayish blue" color you're seeing is not the actual fill color of the fields. It's the "highlight color" that the application uses to show you where fields are located. And you have to disable it to be able to view the real fill color.
Once you've done that you'll see they are most likely white.
You can use the following code to change the fill color based on the selection:
if (event.value=="1") event.target.fillColor = color.red;
else if (event.value=="2") event.target.fillColor = color.blue;
else if (event.value=="2") event.target.fillColor = color.green;
etc.
The color object only supports certain pre-defined color names, though, but you can specify any RGB value you wish, like this:
else if (event.value=="3") event.target.fillColor = ["RGB", 0, 1, 1];
Note the values are between 0 and 1, not 0 and 255, as you see elsewhere.
Make sure to also enable the option to commit the selected value of the drop-down fields immediately (under their Properties, Options tab). Otherwise the script will only execute once you exit the field.
Copy link to clipboard
Copied
Wow...
Many thanks for the fast reply.
Peter
Copy link to clipboard
Copied
Last question...
How do I disable the default HIGHLIGHT?
Copy link to clipboard
Copied
found it OK...
Thanks again for your help.
Peter
Copy link to clipboard
Copied
var f = this.getField("NewTest01").value; {
if (f=1.00) event.target.fillColor = color.red; else
if (f>1.00 && f<2.00) event.target.fillColor = color.yellow;
else if (f=>2 && f<3) event.target.fillColor = color.green; else
if (f=>3&&f<4) event.target.fillColor = color.blue;else
event.target.fillColor = color.white;
}
The above coding changes the background to RED....regardless of what number selected from the combo box in the series of 1 / 1.5 / 2 / 2.5 / 3 / 3.5 / 4.
What Have I left out?
Thanking you in advance...
Peter
Copy link to clipboard
Copied
You have some errors. Try this code:
var f = this.getField("NewTest01").value;
if (f==1.00) event.target.fillColor = color.red;
else
if (f>1.00 && f<2.00) event.target.fillColor = color.yellow;
else if (f>=2 && f<3) event.target.fillColor = color.green; else
if (f>=3&&f<4) event.target.fillColor = color.blue;else
event.target.fillColor = color.white
Copy link to clipboard
Copied
worked perfectly...
Thank you so very much.
Peter
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more