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

Help changing font color in text field based on value entered by user

Community Beginner ,
Sep 28, 2024 Sep 28, 2024

Help!  I'm trying to change the font color of a text field based on the value entered by user.  I currently have the below code in the custom format tab - the first part works; if the user enters "PLATINUM"  in the field, the text changes to gray.  But when the user enters "GOLD", it does not change to orange.  I also have a custom keystroke script to change the text to upper case.

if(event.value=="PLATINUM")
{
event.target.textColor=color.gray
this.getField("VSC Program").textColor=gray;
}
else if(event.value=="GOLD")
{
event.target.textColor=color.orange
this.getField("VSC Program").textColor=orange;
}

 

I've also tried this script, and it does not work either:

 

if(event.value=="PLATINUM") event.target.textColor = color.gray;
else if (event.value=="GOLD") event.target.textColor = color.orange;
else event.target.textColor = color.black;

 

What am I doing wrong?

 

Any help is greatly appreciated!

 

TOPICS
JavaScript , PDF forms
319
Translate
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 Expert ,
Sep 28, 2024 Sep 28, 2024

You can't use every color name with color.xx.  These are the only colors you can use with this format:

transparent
black
white
dkGray
gray
ltGray
red
green
blue
cyan
magenta
yellow

For orange use event.target.textColor=["RGB", 1,0.439208984375,0.007843017578125].

To obtain the RGB for a specific color, set the text color manually in a field then run the following script in the console:

this.getField("Text1").textColor

Translate
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 Expert ,
Sep 28, 2024 Sep 28, 2024
LATEST

There is also an issue when you try to set color to "VSC Program" field, you can't just enter color name you need to use color object e.g. color.blue or use RGB color codes.

To make it easier to use RGB color codes just find RGB color code online and use like this, for example RGB color code for orange is 255 136 0 use like this: ["RGB", 255/255, 136/255, 0/255]

Translate
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