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

Custom Format Scrip

Explorer ,
May 05, 2016 May 05, 2016

I hope I've posted this in the right place, I'm working on a form in Adobe Acrobat 9.  I have a combo box in a form, with Low, Medium, High and No Action Required as the options.  What I would like to do is change the colour of the field (either text or background) based on the selection such as

Low - Green

Medium - Orange

High - Red

No Action Required - no change.

Can this be done?

TOPICS
Acrobat SDK and JavaScript , Windows
560
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

correct answers 1 Correct answer

LEGEND , May 05, 2016 May 05, 2016

If you mean that you want to change the background color of the combo box, you can use the following custom validate script:

// Custom Validate script for text field

switch (event.value) {

case "Low" :

    event.target.fillColor = color.green;

    break;

case "Medium" :

    event.target.fillColor = ["RGB", 1, .33, 0];

    break;

case "High" :

    event.target.fillColor = color.red;

    break;

case "No Action Required" :

    event.target.fillColor = color.white;

    break;

}

Translate
LEGEND ,
May 05, 2016 May 05, 2016

If you mean that you want to change the background color of the combo box, you can use the following custom validate script:

// Custom Validate script for text field

switch (event.value) {

case "Low" :

    event.target.fillColor = color.green;

    break;

case "Medium" :

    event.target.fillColor = ["RGB", 1, .33, 0];

    break;

case "High" :

    event.target.fillColor = color.red;

    break;

case "No Action Required" :

    event.target.fillColor = color.white;

    break;

}

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
Explorer ,
May 05, 2016 May 05, 2016

Thank you so much, it now works perfectly, you've made my day

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
Explorer ,
May 10, 2016 May 10, 2016

Can I call on your expertise once again?

I now have another field (text) which i need to complete automatically based on the response to the preceding drop down list field for example

When the user selects  High, Medium or Low from field A text will appear in field B based on the selection above ie Selecting High in field A will auto populate Field B with the following text, "his is serious and must receive urgent attention" and the text will change when selecting Medium or Low.

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
LEGEND ,
May 10, 2016 May 10, 2016

At the beginning of the script, add the following line of code:

var f1 = getField("Field B");

but replace "Field B" with the actual name of the text field. Then, just before each break statement, add a line like this:

f1.value = "his is serious and must receive urgent attention";

but change the text according to which item is selected.

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
Explorer ,
May 10, 2016 May 10, 2016

Thanks George, I'd just posted my query when your response came through.

I've tried your code but couldn't get it to work, to be honest I don't really know what I'm doing, it's a bit like giving a monkey a shotgun.

Do I add it to the other code you gave me last week or does it goes somewhere else?  Sorry to be a pain,

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
LEGEND ,
May 10, 2016 May 10, 2016

Yes, alter the previous code as I described. If it doesn't work, post your new script here so I know what you've changed it to.

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
Explorer ,
May 10, 2016 May 10, 2016

Thank you so much George, that is brilliant.

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 ,
Sep 21, 2016 Sep 21, 2016

Hi, I am hoping you can help me. Your code worked perfectly! The only problem is, I am trying to change the RGB to colors that match my pdf. Your example RGB works great, however when I insert my RGB it doesn't work at all and I can't figure out why.

Here is my code:

// Custom Validate script for text field

switch (event.value) {

case "Yes" :

    event.target.fillColor = color.green;

    break;

case "No" :

    event.target.fillColor = ["RGB", 1, .33, 0];

    break;

case "1 x per week" :

    event.target.fillColor = ["RGB", 146, 200, 78];

    break;

case "select one" :

    event.target.fillColor = color.gray;

    break;

}

The event.target line in NO is your code and it changes to red. the event.target line in 1x per week is the green color I am using elsewhere in my pdf, but when I select 1 x per week, it goes white. Any ideas?

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
LEGEND ,
Sep 21, 2016 Sep 21, 2016
LATEST

The individual numbers in the array range from 0 to 1, not 0 to 255, so use this instead:

    event.target.fillColor = ["RGB", 146/255, 200/255, 78/255];

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