Dropdown box selection to change background color of text field

Community Beginner ,
Jul 14, 2019 Jul 14, 2019

Copy link to clipboard

Copied

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

Views

1.8K

Likes

Translate

Translate

Report

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

Likes

Translate

Translate
Most Valuable Participant ,
Jul 14, 2019 Jul 14, 2019

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Following line is incorrect:

else "indicator_1_earlies".fillColor = color.transparent;

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Where does you set the variable value?

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Your first code is better. Where did you place it, though?

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Ah yes!  I have removed it - thanks

Likes

Translate

Translate

Report

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