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

Need dropdown list or list box to change color based on selection

Community Beginner ,
Sep 29, 2023 Sep 29, 2023

i have a form that i want to place several boxes to fill with either red, yellow or green.  i want to be able to place a list box or dropdown box in a rectangle and if i select red from the list i want the box to fill red with red font so it just looks like a filled in red box. likewise for yellow and green

TOPICS
How to , JavaScript , PDF forms
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 ,
Sep 29, 2023 Sep 29, 2023

It's hard to help without knowing actual field names and how many are there, that photo doesn't help anything.

When ask for help, try to include all information.

Here is a basic script how to change border and text color of a text field depending on dropdown selection, just change "Text Field" to your actual text field name and use script as 'Validate' script of dropdown field:

var f = this.getField("Text Field");

if(event.value == "Red"){
f.textColor = color.red;
f.strokeColor = color.red;}

else if(event.value == "Yellow"){
f.textColor = color.yellow;
f.strokeColor = color.yellow;}

else if(event.value == "Green"){
f.textColor = color.green;
f.strokeColor = color.green;}

else{
f.textColor = color.black;
f.strokeColor = color.black;}

 

 

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 ,
Sep 30, 2023 Sep 30, 2023
thank you for your reply. i have attached a wider image and shown where i
copied your script to execute my idea. however when i make a selection the
font still remains the color selected in the appearance tab in the
properties. can you help with that?

--
Aaron Shade
Owner - Master Plumber
First Star Plumbing
214-298-2530
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 ,
Sep 30, 2023 Sep 30, 2023

i changed the script a bit and I think it works

var f = this.getField("Dropdown1");

if(event.value == "red"){
f.textColor = color.red;
f.strokeColor = color.red;
f.fillColor = color.red}

else if(event.value == "yellow"){
f.textColor = color.yellow;
f.strokeColor = color.yellow;
f.fillColor = color.yellow}

else if(event.value == "green"){
f.textColor = color.green;
f.strokeColor = color.green;
f.fillColor = color.green}

else if(event.value == "white"){
f.textColor = color.white;
f.strokeColor = color.white;
f.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
Community Beginner ,
Sep 30, 2023 Sep 30, 2023

another update... it doesn't work on adobe acrobat reader on my ipad, only on desktop. anybody help for that?  that is primarily where i would want to use it, in 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
Community Beginner ,
Sep 30, 2023 Sep 30, 2023

another update... adobe mobile doesn't recognize scripts i guess???  downloaded pdf expert to open file and can make color selections on free version but cannot comment when needed.  will probably purchase editing feature unless adobe gets it act together to read scripts created in its own desktop app.  smh

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 ,
Sep 30, 2023 Sep 30, 2023
LATEST

Different PDF viewers have differnt levels of compliance with the Acrobat JavaScript model.

The desktop Acrobat Pro and Rearder, as well as some of the better 3rd Party PDF viewers, have the highest level of compliance. The Acrobat mobile viewer has less. It only provides support for basic calcualtions and some list handling. PDF Expert is better than Acrobat mobile. But all others such as the browser viewers, or just about any mobile viewer have very poor, or zero, compliance. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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