Change text color of a value depending on an other fields value

New Here ,
Aug 04, 2019 Aug 04, 2019

Copy link to clipboard

Copied

Hi, I like to create an pdf form with acrobat. for this i have a table with different fields. depending on the value entered in p.e field "A" the text of field "A". "textA" an "textB" should colored red, etc. (like in the table below)

Headline 1
Headline 2Headline 3
AtextAtextB
1text1text2
ItextItextII

I have been using the forums to help me answer the question above and I have managed to create the code below, but it's not working

if (event.value=="a") { event.target.textColor = color.red;

      this.getField("textA").textColor = red;

      this.getField("textB").textColor = red; }

else if (event.value=="b") { event.target.textColor = color.red; {

      this.getField("textA").textColor = red;

      this.getField("textB").textColor = red; }

else if (event.value>="0") { event.target.textColor = color.blue; {

      this.getField("textA").textColor = blue; 

      this.getField("textB").textColor = blue; }

else if (event.value=="I") { event.target.textColor = color.green; {

    this.getField("textA").textColor = green;

    this.getField("textB").textColor = green; }

else if (event.value=="II") { event.target.textColor = color.green; {

    this.getField("textA").textColor = green;

    this.getField("textB").textColor = green; }

else event.target.textColor = color.black;

Can anyone suggest what I might be doing wrong?

TOPICS
Acrobat SDK and JavaScript

Views

193

Likes

translate

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

Adobe Community Professional , Aug 05, 2019 Aug 05, 2019
You use too many {

Likes

translate

Translate

Translate
Adobe Community Professional ,
Aug 04, 2019 Aug 04, 2019

Copy link to clipboard

Copied

Look at the console for errors.

Likes

translate

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
Most Valuable Participant ,
Aug 05, 2019 Aug 05, 2019

Copy link to clipboard

Copied

You need to be consistent. Why are you using "color.red" in one spot and just "red" in another? The former is correct. The latter isn't.

Likes

translate

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
Most Valuable Participant ,
Aug 05, 2019 Aug 05, 2019

Copy link to clipboard

Copied

Another thing to be consistent about is how you treat your variables. If it's a string then you need to put double-quotes around it (as you did), but if it's a number then you shouldn't do that, like you did here:

(event.value>="0")

Likes

translate

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
New Here ,
Aug 05, 2019 Aug 05, 2019

Copy link to clipboard

Copied

thank you for your answers, I took the changes, but still get the syntax-error 7 in line 8

if (event.value=="a") { event.target.textColor = color.red; 

        this.getField("textA").textColor = color.red; 

        this.getField("textB").textColor = color.red; } 

else if (event.value=="b") { event.target.textColor = color.red; { 

        this.getField("textA").textColor = color.red; 

        this.getField("textB").textColor = color.red; } 

else if (event.value>=0) { event.target.textColor = color.blue; { 

        this.getField("textA").textColor = color.blue;   

        this.getField("textB").textColor = color.blue; } 

else if (event.value=="I") { event.target.textColor = color.green; { 

        this.getField("textA").textColor = color.green; 

        this.getField("textB").textColor = color.green; } 

else if (event.value=="II") { event.target.textColor = color.green; { 

        this.getField("textA").textColor = color.green; 

        this.getField("textB").textColor = color.green; } 

else event.target.textColor = color.black;

Likes

translate

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
Adobe Community Professional ,
Aug 05, 2019 Aug 05, 2019

Copy link to clipboard

Copied

You use too many {

Likes

translate

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
New Here ,
Aug 05, 2019 Aug 05, 2019

Copy link to clipboard

Copied

oh no

thank you all, the code is working correctly now

Likes

translate

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