Coloring a field box when a certain condition exists. i.e. Maximum, the field box is yellow.

New Here ,
Dec 31, 2017

Copy link to clipboard

Copied

On the form I am creating, I'm trying to create a criteria that if a field has a certain word in it, it changes color.  For example:  If a classification is Minimum, I want the color of the field box to be blue, if the status is medium, I want the filed box to be brown, Maximum, yellow.  How do I create a javascript for this, I'm sure it's simple, but this is the first form I've created with ADOBE.  Thank you

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

You'll need to use either a validate or format script on the field that is being colored. These events are activated whenever a field value is modified.

Something like this works fine

if(event.value == "Thing1")

   event.target.fillColor = color.yellow;

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

   event.target.fillColor = color.blue;

Here'a an article on the topic that also includes a similar script:

https://acrobatusers.com/tutorials/using-colors-acrobat-javascript

Finally there is a possible impediment to this scheme. If Acrobat/Reader is setup to highlight form fields, then the color changes may not be seen. You might want to add this code to a document script to turn off highlighting when the document is opened.

app.runtimeHighlight = false;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

100

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

Coloring a field box when a certain condition exists. i.e. Maximum, the field box is yellow.

New Here ,
Dec 31, 2017

Copy link to clipboard

Copied

On the form I am creating, I'm trying to create a criteria that if a field has a certain word in it, it changes color.  For example:  If a classification is Minimum, I want the color of the field box to be blue, if the status is medium, I want the filed box to be brown, Maximum, yellow.  How do I create a javascript for this, I'm sure it's simple, but this is the first form I've created with ADOBE.  Thank you

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

You'll need to use either a validate or format script on the field that is being colored. These events are activated whenever a field value is modified.

Something like this works fine

if(event.value == "Thing1")

   event.target.fillColor = color.yellow;

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

   event.target.fillColor = color.blue;

Here'a an article on the topic that also includes a similar script:

https://acrobatusers.com/tutorials/using-colors-acrobat-javascript

Finally there is a possible impediment to this scheme. If Acrobat/Reader is setup to highlight form fields, then the color changes may not be seen. You might want to add this code to a document script to turn off highlighting when the document is opened.

app.runtimeHighlight = false;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

101

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
Dec 31, 2017 0
Adobe Community Professional ,
Dec 31, 2017

Copy link to clipboard

Copied

You'll need to use either a validate or format script on the field that is being colored. These events are activated whenever a field value is modified.

Something like this works fine

if(event.value == "Thing1")

   event.target.fillColor = color.yellow;

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

   event.target.fillColor = color.blue;

Here'a an article on the topic that also includes a similar script:

https://acrobatusers.com/tutorials/using-colors-acrobat-javascript

Finally there is a possible impediment to this scheme. If Acrobat/Reader is setup to highlight form fields, then the color changes may not be seen. You might want to add this code to a document script to turn off highlighting when the document is opened.

app.runtimeHighlight = false;

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
Reply
Loading...
Dec 31, 2017 0