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

using pull-down menu value changes with color changes

New Here ,
Oct 24, 2019 Oct 24, 2019

I am trying to have the background fill color and font color change dependant on the value in a PULL-DOWN menu and once the color changes ...to remain at the newly coded color.  I am using a text field in a PDF file accessed with Adobe Acrobat.

 

Peter

1.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
Community Expert ,
Oct 25, 2019 Oct 25, 2019

What have you tried so far, and what were the results?

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
New Here ,
Oct 25, 2019 Oct 25, 2019

Thanks for the quick reply.

I am new to coding in Acrobat and really don't have a clue.

What I am trying to do is the following:

  • I've set up pull-down menus with 7 numeric values...so seven(7) items in the drop-down combo
  • When the user selects a numeric value,  I want the fill color of the box to change to another color other than the default value ---greyish blue.
  • I also would like the new color to remain with the changed value.

Thank you...

 

Peter

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 ,
Oct 25, 2019 Oct 25, 2019

OK. First of all, the "grayish blue" color you're seeing is not the actual fill color of the fields. It's the "highlight color" that the application uses to show you where fields are located. And you have to disable it to be able to view the real fill color.

Once you've done that you'll see they are most likely white.

You can use the following code to change the fill color based on the selection:

 

if (event.value=="1") event.target.fillColor = color.red;

else if (event.value=="2") event.target.fillColor = color.blue;

else if (event.value=="2") event.target.fillColor = color.green;

etc.

 

The color object only supports certain pre-defined color names, though, but you can specify any RGB value you wish, like this:

else if (event.value=="3") event.target.fillColor = ["RGB", 0, 1, 1];

Note the values are between 0 and 1, not 0 and 255, as you see elsewhere.

 

Make sure to also enable the option to commit the selected value of the drop-down fields immediately (under their Properties, Options tab). Otherwise the script will only execute once you exit the field.

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
New Here ,
Oct 25, 2019 Oct 25, 2019

Wow...

Many thanks for the fast reply.

 

Peter

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
New Here ,
Oct 25, 2019 Oct 25, 2019

Last question...

How do I disable the default HIGHLIGHT?

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
New Here ,
Oct 25, 2019 Oct 25, 2019

found it OK...

Thanks again for your help.

Peter

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
New Here ,
Oct 25, 2019 Oct 25, 2019

var f = this.getField("NewTest01").value; {
if (f=1.00) event.target.fillColor = color.red; else
if (f>1.00 && f<2.00) event.target.fillColor = color.yellow;
else if (f=>2 && f<3) event.target.fillColor = color.green; else
if (f=>3&&f<4) event.target.fillColor = color.blue;else
event.target.fillColor = color.white;
}

The above coding changes the background to RED....regardless of what number selected from the combo box in the series  of 1 / 1.5 / 2 / 2.5 / 3 / 3.5 / 4.

What Have I left out?

Thanking you in advance...

 

Peter

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 ,
Oct 25, 2019 Oct 25, 2019

You have some errors. Try this code:

 

var f = this.getField("NewTest01").value;
if (f==1.00) event.target.fillColor = color.red;

else
if (f>1.00 && f<2.00) event.target.fillColor = color.yellow;
else if (f>=2 && f<3) event.target.fillColor = color.green; else
if (f>=3&&f<4) event.target.fillColor = color.blue;else
event.target.fillColor = color.white

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
New Here ,
Oct 25, 2019 Oct 25, 2019
LATEST

worked perfectly...

Thank you so very much.

 

Peter

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