Skip to main content
Inspiring
June 25, 2017
Answered

Change text box fill color on button push

  • June 25, 2017
  • 2 replies
  • 3880 views

Lets say I have Buttons A and B and text field "Text1" I need code so when I press button A it change fill color of text field to(example green) and when i press button B it change text field to green also but if it is already green(because of button A) then change color to (example red).Can you Guys help pls?

This topic has been closed for replies.
Correct answer try67

You can use this code:

var field1 = this.getField("Text1");

if (color.equal(field1.fillColor, color.green)==true) field1.fillColor = color.red;

else field1.fillColor = color.green;

You didn't specify what should happen if the button is clicked is the field is red, though...

2 replies

Asim123Author
Inspiring
June 25, 2017

Exactly what I needed thanks. Can you tell me also how to change colors to RGB?

try67
Community Expert
Community Expert
June 25, 2017

Sure. Instead of color.green or color.red you can use this:

["RGB", 0, 1, 0]

["RGB", 1, 0, 0]

Note that the values are from 0 to 1, not 0 to 255 like in other places.

Asim123Author
Inspiring
June 25, 2017

Thx that did the job.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 25, 2017

You can use this code:

var field1 = this.getField("Text1");

if (color.equal(field1.fillColor, color.green)==true) field1.fillColor = color.red;

else field1.fillColor = color.green;

You didn't specify what should happen if the button is clicked is the field is red, though...