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

Change Color of Text Field from Drop Down Menu Selection

New Here ,
Mar 15, 2019 Mar 15, 2019

Copy link to clipboard

Copied

HI! I want to learn how I can change the color of a text field based on specific selections from a drop down menu. If let's say "Medicaid" is selected from drop down menu field "Insurance Company Name", I would like the text field "Medicaid" to highlight yellow. How can I do that with java script? Thanks!

TOPICS
PDF forms

Views

6.0K

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 Expert , Mar 15, 2019 Mar 15, 2019

As the custom calculation script of text field enter the following code:

event.target.fillColor = (this.getField("Insurance Company Name").valueAsString=="Medicaid") ? color.yellow : color.transparent;

Votes

Translate

Translate
Community Expert ,
Mar 15, 2019 Mar 15, 2019

Copy link to clipboard

Copied

As the custom calculation script of text field enter the following code:

event.target.fillColor = (this.getField("Insurance Company Name").valueAsString=="Medicaid") ? color.yellow : color.transparent;

Votes

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
New Here ,
Mar 15, 2019 Mar 15, 2019

Copy link to clipboard

Copied

You rock! That worked! I have multiple selections that if selected from the drop down I want to change the textfield to yellow. Where would I enter the other selections in your script?

Votes

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 Expert ,
Mar 15, 2019 Mar 15, 2019

Copy link to clipboard

Copied

You can do it like this:

var v = this.getField("Insurance Company Name").valueAsString;

event.target.fillColor = (v=="Medicaid" || v=="Something else" || v=="Yet another thing") ? color.yellow : color.transparent;

Votes

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
New Here ,
Mar 15, 2019 Mar 15, 2019

Copy link to clipboard

Copied

Thank you soooooo much! That worked perfectly!

Votes

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
New Here ,
Feb 13, 2020 Feb 13, 2020

Copy link to clipboard

Copied

Hi, I have another question

What should I write if I want to create different colors for different dropdown options? 

Many thanks 🙂

Votes

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
New Here ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

What should I write if I want to create different colors for different text options?

Votes

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 Expert ,
Feb 18, 2020 Feb 18, 2020

Copy link to clipboard

Copied

Votes

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
New Here ,
Jul 16, 2021 Jul 16, 2021

Copy link to clipboard

Copied

Hello, 

Can someone please help me? I have a dropdown menu in PDF forms in which there are 2 options (text) and I want based on the option that someone chooses the text colour to change. How can I code this in java? 

 

Thank you!

Votes

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 Expert ,
Jul 16, 2021 Jul 16, 2021

Copy link to clipboard

Copied

Well, your inquiry is already addressed here in this thread using Acrobat JavaScript not Java.

 

Acrobat JavaScript is the programming language that the Adobe Acrobat use.

Votes

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
New Here ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

Hello,

I am and in need the same function. The field is called "Ankle DFR" and the selection options are (no commas): Limited, WRL, and Hypermobile. I would like it to turn yellow when I select "Limited" and "Hypermobile". 

 

So I created a drop down menu, opened properities, clicked the calculate tab, and entered the following in the Custom Calculation section:

 

event.target.fillColor = (this.getField("Ankle DFR").valueAsString=="Limited") ? color.yellow : color.transparent;

 

However, it only goes yellow when I click once and see the list of options. But when I select the desired choice, Limited, it goes back to its original color. I would like it to remain yellow (or whatever color), when I select anything other than WRL. Thanks in advance for any help!

Votes

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 Expert ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

At what text field does you use the script?

Votes

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
New Here ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

Hi Bernd

 

Thank you for your reply. Unfortunately I don't quite understand your message. Could you please rephrase? Thanks again. 

Votes

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 Expert ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

Want you change the color of a text field based on specific selections from a drop down menu?

Votes

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 Expert ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

If you want yellow for anything other then "WRL" then use like this and in dropdown field properties under options tab tick 'Commit selected value immediately':

event.target.fillColor = (this.getField("Ankle DFR").valueAsString=="WRL") ? color.transparent : color.yellow;

Votes

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
New Here ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

Hi Nesa

 

Thank you for your response. Where do I paste your code? I did as you suggested by clicking "Commit selected value immediately" and then moved on to the Calculate tab and entered your code in the Custom Calculation section. However, the same thing happens where the drop down menu will turn yellow when I bring up the down menu to see all the options but once I select it seems remains the initial color, not yellow. 

Votes

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 Expert ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

You probably have active field highlights, try turn them off in preferences -> forms -> 'Show border hover color for fields'.

Votes

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
New Here ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

LATEST

Hi Nesa,

 

Thank you so much for your suggestions. My problem has been successfully solved. 

Votes

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