Skip to main content
August 5, 2019
Answered

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

  • August 5, 2019
  • 2 replies
  • 1795 views

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?

This topic has been closed for replies.
Correct answer Bernd Alheit

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;


You use too many {

2 replies

try67
Community Expert
Community Expert
August 5, 2019

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.

try67
Community Expert
Community Expert
August 5, 2019

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")

August 5, 2019

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;

Bernd Alheit
Community Expert
Community Expert
August 5, 2019

Look at the console for errors.