Highlighted

Conditional Formatting Color fill in Adobe Acrobat DC

New Here ,
Aug 28, 2018

Copy link to clipboard

Copied

I am trying to conditionally format a field in my PDF to fill with a certain color based on the selected dropdown list's value. It seems i have gotten some traction, but the only color that works is red, and it does not change colors if I select a different value from my dropdown. I need help with my Javascript. Here is what I have so far:

var v = this.getField("Dropdown4.5").value;

     if (v="Business Now") {event.target.fillColor = color.green;}

     if (v="Business Future") {event.target.fillColor = color.blue;}

     if (v="Daily To-Do's") {event.target.fillColor = color.red;}                   

     if (v="Marketing") {event.target.fillColor = color.orange;}

     if (v="Learning Plan") {event.target.fillColor = color.yellow;}

Stack 3.PNG

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

That first line is missing getField, so it should be:

var v = getField("Dropdown4.8").value;

though it's best to get into the habit of using the valueAsString property instead when you'll be dealing with a field value as a string:

var v = getField("Dropdown4.8").valueAsString;

TOPICS
Acrobat SDK and JavaScript

Views

426

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

Conditional Formatting Color fill in Adobe Acrobat DC

New Here ,
Aug 28, 2018

Copy link to clipboard

Copied

I am trying to conditionally format a field in my PDF to fill with a certain color based on the selected dropdown list's value. It seems i have gotten some traction, but the only color that works is red, and it does not change colors if I select a different value from my dropdown. I need help with my Javascript. Here is what I have so far:

var v = this.getField("Dropdown4.5").value;

     if (v="Business Now") {event.target.fillColor = color.green;}

     if (v="Business Future") {event.target.fillColor = color.blue;}

     if (v="Daily To-Do's") {event.target.fillColor = color.red;}                   

     if (v="Marketing") {event.target.fillColor = color.orange;}

     if (v="Learning Plan") {event.target.fillColor = color.yellow;}

Stack 3.PNG

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

That first line is missing getField, so it should be:

var v = getField("Dropdown4.8").value;

though it's best to get into the habit of using the valueAsString property instead when you'll be dealing with a field value as a string:

var v = getField("Dropdown4.8").valueAsString;

TOPICS
Acrobat SDK and JavaScript

Views

427

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
Aug 28, 2018 0
Most Valuable Participant ,
Aug 28, 2018

Copy link to clipboard

Copied

You're using the wrong operator. The comparison operator in JS is "==". So change all the instances of this code:

if (v="Business Now")

To:

if (v=="Business Now")

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...
Aug 28, 2018 0
New Here ,
Aug 28, 2018

Copy link to clipboard

Copied

try67​ it still seems to not be working. I added the double equal sign, but now no color fills no matter which value is selected. Is the rest of my script correct?

Stack 6.png

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...
Aug 28, 2018 0
Most Valuable Participant ,
Aug 28, 2018

Copy link to clipboard

Copied

Well, you've switched from DropDown4.5 in your first example to DropDown4.8 in your new one.

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...
Aug 28, 2018 0
New Here ,
Aug 28, 2018

Copy link to clipboard

Copied

I tried to format dropdown4.5 too and had no luck, I continued on with a few more drop-down fields and also had no luck. I screenshot the dropdown 4.8 for reference, but it is not changing fill color at all (currently selected "Business Now" that should fill green)

Stack 7.PNG

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...
Aug 28, 2018 0
Adobe Community Professional ,
Aug 28, 2018

Copy link to clipboard

Copied

That first line is missing getField, so it should be:

var v = getField("Dropdown4.8").value;

though it's best to get into the habit of using the valueAsString property instead when you'll be dealing with a field value as a string:

var v = getField("Dropdown4.8").valueAsString;

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...
Aug 28, 2018 0
New Here ,
Aug 28, 2018

Copy link to clipboard

Copied

Boom! That worked exactly as expected. Thank you George_Johnson

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...
Aug 28, 2018 0
Most Valuable Participant ,
Aug 28, 2018

Copy link to clipboard

Copied

You had it correct in the original code you posted... Not sure why you changed it later on.

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...
Aug 28, 2018 0
New Here ,
Oct 14, 2020

Copy link to clipboard

Copied

Hi! 

I am trying to conditionally format a field in my PDF to fill with a certain color based on the selected dropdown list's value. I tried adapting solutions provided to others with the same request. Unfortunately I don't understand enough about the script to come up with the right solution. I've been trying for days and would really appreciate help. 

 

Thank you!!

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...
Oct 14, 2020 0
try67 LATEST
Most Valuable Participant ,
Oct 14, 2020

Copy link to clipboard

Copied

You need to provide more details if you want to have help... What did you try? What were the results? What are you tryign to achieve, exactly?

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...
Oct 14, 2020 0