Help changing font color in text field based on value entered by user
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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]

