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

Dropdown menu in different colors

Community Beginner ,
Aug 31, 2020 Aug 31, 2020

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

TOPICS
Create PDFs , Edit and convert PDFs , PDF forms , Standards and accessibility
5.3K
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
1 ACCEPTED SOLUTION
Community Expert ,
Sep 01, 2020 Sep 01, 2020

Use the script without the first line as validation script.

View solution in original post

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

Where does you use the script?

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

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!

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

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

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

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.

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

Use the script without the first line as validation script.

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 02, 2020 Sep 02, 2020

Thank you! It worked

Never not learning 

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

Hi,

 

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

 

BarlaeDC_0-1598887175764.pngexpand image

 

Regards

 

Malcolm

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

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

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

Thank you Nesa

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

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.

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

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.

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

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

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

This part of it is not needed:

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

event.target.fillColor = color.transparent;

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

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

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

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.

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 ,
Jun 30, 2022 Jun 30, 2022

Hi everyone, I need to do the same but I'm confused as to which tab on the dropdown list the code belongs? Does it go into Format? 

 

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 ,
Jun 30, 2022 Jun 30, 2022

Place it as a Validation script.

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 26, 2023 Oct 26, 2023

Hi all, I need to create a RAG colour system using corporate colours in a dropdown list for the user to select next to some text they need to insert. I have tried inserting the code and using corporate colours but sometimes reverts to rgb colours and in some cases Amber reverts to red and the colours don't stay the go transparent when deselected. I'm clearly doing something wrong. Is there a step-by-step guide/video on how to do this please. 

 

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 26, 2023 Oct 26, 2023
LATEST

You can use following color spaces:
Transparent, Gray, RGB, or CMYK

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