Skip to main content
Inspiring
May 15, 2017 1:52 PM UTC
Answered

How do you change font and background colour based on calculated result

Hi,

Hoping you can help.

I’m trying to get a specific result shown, with a particular font colour and background colour to the text field after adding up a calculation based on radio buttons.

I can do the showing of the specific result (shown below, attached to a text field), but am struggling to go get the colour changes to work…can anyone help?

var nResult = this.getField("Result").value;

if( nResult > 26 ) event.value = “TEXT BLOCK 1. (27-36)";

else if( nResult > 15 ) event.value = “TEXT BLOCK 2. (16-26)";

else event.value = “TEXT BLOCK 3. (0-15)";

Is it something to do with this? event.target.fillColor = color.#FFFFFF : color.#800000;

I can’t work out where to put it so it works…

Huge thanks in advance

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
May 15, 2017 3:47 PM UTC

For example:

if ( nResult > 26 ) {

     event.value = "TEXT BLOCK 1. (27-36)";

     event.target.textColor = ["RGB", 1, 0, 0];

     event.target.fillColor = ["RGB", 0, 0, 1];

}

4 replies

try67
Community Expert
Community Expert
May 15, 2017 2:41 PM UTC

The right syntax is:

event.target.fillColor = ["RGB", 0.2, 0.5, 1];

The color above is just a random one. You can specify any values you want, just keep in mind they range from 0 to 1, not 0 to 255 or 00 to FF...

Translate
Inspiring
May 15, 2017 3:45 PM UTC

Hi try67,

Thanks for the reply and very useful to know how to specify the colour. Do you know where this would sit in the JS below, and how I say apply X colour to the font and Y colour to the background?

var nResult = this.getField("Result").value;

if( nResult > 26 ) event.value = “TEXT BLOCK 1. (27-36)";

else if( nResult > 15 ) event.value = “TEXT BLOCK 2. (16-26)";

else event.value = “TEXT BLOCK 3. (0-15)";

Thanks

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 15, 2017 3:47 PM UTC

For example:

if ( nResult > 26 ) {

     event.value = "TEXT BLOCK 1. (27-36)";

     event.target.textColor = ["RGB", 1, 0, 0];

     event.target.fillColor = ["RGB", 0, 0, 1];

}

Translate