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

Change text box fill color on button push

Enthusiast ,
Jun 25, 2017 Jun 25, 2017

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?

TOPICS
PDF forms
4.0K
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
1 ACCEPTED SOLUTION
Community Expert ,
Jun 25, 2017 Jun 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...

View solution in original post

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 ,
Jun 25, 2017 Jun 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...

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
Enthusiast ,
Jun 25, 2017 Jun 25, 2017

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

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 ,
Jun 25, 2017 Jun 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.

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
Enthusiast ,
Jun 25, 2017 Jun 25, 2017

Thx that did the job.

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
Contributor ,
Dec 27, 2023 Dec 27, 2023

Hi @try67 
How could I use these colors instead of green and red:
["RGB", 228, 229, 230]

["RGB", 255, 192, 0]

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 ,
Dec 28, 2023 Dec 28, 2023

You can use RGB colors like this: ["RGB", 228/255, 229/255, 230/255]

If you want to compare RGB colors using color.equal it's a bit trickier.

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
Contributor ,
Dec 28, 2023 Dec 28, 2023
LATEST

Thank you, it's working very well

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