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

Dropdown box selection to change background color of text field

Community Beginner ,
Jul 14, 2019 Jul 14, 2019

Hello,  I wonder if anyone could please point me in the right direction of how to achieve the following:

Acrobat DC

I have a drop-down box which contains five items.  I have managed to change the colour of the text for each item when selected within the drop-down box.  What I would really like to do is to change the background colour of 5 different text fields as well.  So selecting item 1 turns the text red in the drop-down and also makes the background colour of a text field red.  selecting item 2 makes the text turn blue in the drop-down and also makes the background of an additional text field blue.  And so forth...  No selection means the colour is transparent.

I cannot get my head around this.  If anyone could please point me in the right direction I would be eternally grateful.

TOPICS
Acrobat SDK and JavaScript , Windows
7.7K
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

correct answers 1 Correct answer

Community Beginner , Jul 16, 2019 Jul 16, 2019

Ok, I worked it out!

I have the code in the 'Custom calculation script' for the text box.  "input_project_1_early" is the drop down.

event.value=this.getField("input_project_1_early").value;

if (event.value=="MS")

    event.target.fillColor = color.blue;

else if (event.value=="PA")

    event.target.fillColor = color.magenta;

else if (event.value=="GP")

    event.target.fillColor = color.green;

else if (event.value=="AP")

    event.target.fillColor = color.red;

else if (event.value=="i")

    event.target.fi

...
Translate
Community Expert ,
Jul 14, 2019 Jul 14, 2019

Simply set the field's fillColor property, just like you did with the textColor property to change the color of the text.

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 Beginner ,
Jul 15, 2019 Jul 15, 2019

Hmmmm.  I still cannot get this to work.  I have entered the following into the custom validation script for the text box:

var indicator = this.getField("input_project_1_earlies").value; {

if (indicator=="1")

    event.target.fillColor = color.blue;

else if (indicator=="2")

    event.target.fillColor = color.magenta;

else if (indicator=="3")

    event.target.fillColor = color.green;

else if (indicator=="4")

   event.target.fillColor = color.red;

else "indicator_1_earlies".fillColor = color.transparent;

The dropdown box has the export value of each of the entries set as 1 to 5 and commit value immediately.

I feel like i'm going about this in completely the wrong way?

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 ,
Jul 16, 2019 Jul 16, 2019

Following line is incorrect:

else "indicator_1_earlies".fillColor = color.transparent;

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 Beginner ,
Jul 15, 2019 Jul 15, 2019

Is anyone able to tell me why this doesn't work?  From all the searching I have done I cannot see how else this is possible?

var newFillColor;

var value; 

if (value=="1") newFillColor = color.blue;

else if (value=="2") newFillColor = color.magenta;

else if (value=="3") newFillColor = color.green;

else if (value=="4") newFillColor = color.red;

else if (value=="5") newFillColor = color.yellow;

else newFillColor = color.transparent;  

event.target.fillColor = newFillColor;

this.getfield("input_project_1_early").value=value

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 ,
Jul 15, 2019 Jul 15, 2019

Where does you set the variable value?

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 ,
Jul 16, 2019 Jul 16, 2019

Your first code is better. Where did you place it, 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
Community Beginner ,
Jul 16, 2019 Jul 16, 2019

Ok, I worked it out!

I have the code in the 'Custom calculation script' for the text box.  "input_project_1_early" is the drop down.

event.value=this.getField("input_project_1_early").value;

if (event.value=="MS")

    event.target.fillColor = color.blue;

else if (event.value=="PA")

    event.target.fillColor = color.magenta;

else if (event.value=="GP")

    event.target.fillColor = color.green;

else if (event.value=="AP")

    event.target.fillColor = color.red;

else if (event.value=="i")

    event.target.fillColor = color.black;

else

    event.target.fillColor = color.transparent;

    event.target.fontColor = color.transparent;

works like a charm.

Thanks everyone for their replies.

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 ,
Jul 16, 2019 Jul 16, 2019

Be aware that this line will be executed no matter what value is selected:

event.target.fontColor = color.transparent;

Luckily, there's no such property as "fontColor", so it doesn't really do anything... You should actually remove it.

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 Beginner ,
Jul 16, 2019 Jul 16, 2019
LATEST

Ah yes!  I have removed it - thanks

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