Skip to main content
Inspiring
May 15, 2017
Answered

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

  • May 15, 2017
  • 1 reply
  • 1232 views

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 has been closed for replies.
Correct answer try67

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];

}

1 reply

try67
Community Expert
Community Expert
May 15, 2017

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...

Inspiring
May 15, 2017

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

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 15, 2017

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];

}