Highlighted

Dropdown menu in different colors

Community Beginner ,
Aug 31, 2020

Copy link to clipboard

Copied

Hi, 

Being a beginner at Javascript and have been looking and searching for the right code. 

I really hope that you can help me.

 

I have created a fillable PDF with a dropdown menus. The dropdowns have 4 options and want each option to result in a color.

This is the script I currently have been working on and saw that a similair problem somewhere, but their where no problems there.

 

Script: 

event.value=this.getField("Dropdown93").value;

if (event.value=="W1")

event.target.fillColor = color.red;

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

event.target.fillColor = color.orange;

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

event.target.fillColor = color.yellow;

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

event.target.fillColor = color.transparent;

else

event.target.fillColor = color.transparent;

 

The dropdownboxes and background colors (of the boxes) are all red and do not change color. It doesn't matter which result I pick. It stays red. Something is wrong, but do not know what. 

 

I will be very greatfull if someone could help me with this.

 

Thank you very much!


Arti

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Use the script without the first line as validation script.

TOPICS
Create PDFs, Edit and convert PDFs, PDF forms, Standards and accessibility

Views

86

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

Dropdown menu in different colors

Community Beginner ,
Aug 31, 2020

Copy link to clipboard

Copied

Hi, 

Being a beginner at Javascript and have been looking and searching for the right code. 

I really hope that you can help me.

 

I have created a fillable PDF with a dropdown menus. The dropdowns have 4 options and want each option to result in a color.

This is the script I currently have been working on and saw that a similair problem somewhere, but their where no problems there.

 

Script: 

event.value=this.getField("Dropdown93").value;

if (event.value=="W1")

event.target.fillColor = color.red;

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

event.target.fillColor = color.orange;

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

event.target.fillColor = color.yellow;

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

event.target.fillColor = color.transparent;

else

event.target.fillColor = color.transparent;

 

The dropdownboxes and background colors (of the boxes) are all red and do not change color. It doesn't matter which result I pick. It stays red. Something is wrong, but do not know what. 

 

I will be very greatfull if someone could help me with this.

 

Thank you very much!


Arti

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Use the script without the first line as validation script.

TOPICS
Create PDFs, Edit and convert PDFs, PDF forms, Standards and accessibility

Views

87

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 31, 2020 0
Adobe Community Professional ,
Aug 31, 2020

Copy link to clipboard

Copied

Where does you use the script?

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 31, 2020 1
Community Beginner ,
Aug 31, 2020

Copy link to clipboard

Copied

Hi Bernd,

I used the script on the dropdown menu. All of the menu's contain the same possibility, W1 or W2 or W3 or (leeg).

The dropdown menu's all have a different numbers. I could send a sheet, if it makes it easier?

 

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...
Aug 31, 2020 0
Adobe Community Professional ,
Aug 31, 2020

Copy link to clipboard

Copied

Does you use the script at validation, calculation, or what?

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 31, 2020 0
Community Beginner ,
Sep 01, 2020

Copy link to clipboard

Copied

At first I wrote is as a validation, but now I have to think about it.

Nesa (posted below) to have one with a calculation and I am still in a learning phase. So today, at this point, not knowing what to do. But still want to learn to do this correctly.

But have to create a calculation for this form.

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...
Sep 01, 2020 0
Adobe Community Professional ,
Sep 01, 2020

Copy link to clipboard

Copied

Use the script without the first line as validation script.

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...
Sep 01, 2020 0
Community Beginner ,
Sep 02, 2020

Copy link to clipboard

Copied

Thank you! It worked

Never not learning 

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...
Sep 02, 2020 0
Adobe Community Professional ,
Aug 31, 2020

Copy link to clipboard

Copied

Hi,

 

Do you have the "Commit selected value immediately" check or not ?

 

BarlaeDC_0-1598887175764.png

 

Regards

 

Malcolm

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 31, 2020 1
Engaged ,
Aug 31, 2020

Copy link to clipboard

Copied

There is no "color.orange" use rgb code for orange color or use some other color.

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 31, 2020 1
Community Beginner ,
Aug 31, 2020

Copy link to clipboard

Copied

Thank you Nesa

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 31, 2020 0
Community Beginner ,
Aug 31, 2020

Copy link to clipboard

Copied

Hi Malcom,

 

The check value is on, changed the orange to magenta, but it's not working.

keep thinking about it, but can't see the problem.

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 31, 2020 0
Most Valuable Participant ,
Aug 31, 2020

Copy link to clipboard

Copied

There's also no color.magneta object. You can't just invent stuff and expect it to work...

 

What's the point of the first line, though? Do you want the value of this field to always be the same as another field ("Dropdown93")? If so, why make it a drop-down field? Just use a simple text field.

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 31, 2020 0
Engaged ,
Aug 31, 2020

Copy link to clipboard

Copied

This code is working for me:

if (event.value=="W1")

event.target.fillColor = color.red;

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

event.target.fillColor = color.magenta;

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

event.target.fillColor = color.yellow;

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

event.target.fillColor = color.transparent;

else

event.target.fillColor = color.transparent;

use it as custom calculation script

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 31, 2020 0
Most Valuable Participant ,
Aug 31, 2020

Copy link to clipboard

Copied

This part of it is not needed:

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

event.target.fillColor = color.transparent;

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 31, 2020 0
Most Valuable Participant ,
Aug 31, 2020

Copy link to clipboard

Copied

PS. It's better to use it as a validation script, since you're not actually setting the value.

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 31, 2020 0
Community Beginner ,
Sep 01, 2020

Copy link to clipboard

Copied

I still have a lot to learn, so thank you for helping me.

Working with simple text would be great, but would take the people who use the form a ot of time filling it in. 

So, I'll try the script that Nesa send and will get back to you with an answer.

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...
Sep 01, 2020 0