Copy link to clipboard
Copied
This seems somthing that should be easy, but I cannot get it to work, or maybe it just cannot be done!
Bascially, I have a field which background can be red, yellow or green.
I have a checkbox, that will make the color change. I want to change the color to yellow, only if the field is green. If the field is red, it will stay red.
if ((this.getField("AS").value == "1") && (this.getField("Exercise").fillColor == color.green))
{this.getField("Exercise").fillColor = color.yellow;}
This code doesn't change to color of the field.
When I try fillColor = color.green; the color changes to yellow, even if it's red.
Colors can't be compared with the "==" symbol. Colors are more complex than this. Fortunately there is a color compare function in the SDK.
Here's the reference entry:
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#equal
Here's the updated code
if ((this.getField("AS").value == "1") && color.equal(this.getField("Exercise").fillColor, color.green))
{this.getField("Exercise").fillColor = color.yellow;}
There may be other things that need addressing. For
...Copy link to clipboard
Copied
Colors can't be compared with the "==" symbol. Colors are more complex than this. Fortunately there is a color compare function in the SDK.
Here's the reference entry:
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#equal
Here's the updated code
if ((this.getField("AS").value == "1") && color.equal(this.getField("Exercise").fillColor, color.green))
{this.getField("Exercise").fillColor = color.yellow;}
There may be other things that need addressing. For example, is the name of the checkbox field "AS"? Is this code in the MouseUp event of the checkbox? (If so the code should be written differently). Are there other scripts that are competing to set the color of the field? Where are those scripts? what events are triggering them?
Copy link to clipboard
Copied
Thank you so much Thom.
The code works wonderfully. The script is placed in the calculation tab of a text box, so no need to change the code.
All the other scripts are already taken care of.