• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Change fill.Color to yellow only if previous color is green

Community Beginner ,
Dec 06, 2022 Dec 06, 2022

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.

TOPICS
Acrobat SDK and JavaScript

Views

360

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 06, 2022 Dec 06, 2022

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

...

Votes

Translate

Translate
Community Expert ,
Dec 06, 2022 Dec 06, 2022

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?  

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines