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

Script for Form Field Color Based on Specific Text

Guest
Jan 12, 2016 Jan 12, 2016

I'm working on a form and have a question concerning a few of the fields.

I have a drop-down field that will have 4 options - Urgent Intervention, Intervention, On Watch, and At/Above Benchmark

I'm looking for a script that would change the field color based on which option was selected. I need the field to be red if Urgent Intervention is selected, yellow if Intervention is selected, blue for On Watch, and green for At/Above Benchmark.

I don't know much about scripts, and I've tried to find options, but I can't find anything that works.

Thanks in advance.

TOPICS
Acrobat SDK and JavaScript , Windows
363
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 ,
Jan 12, 2016 Jan 12, 2016

You can control either the text color, the background color, or the border color. Can you clarify which you want?

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
Guest
Jan 12, 2016 Jan 12, 2016

I am referring to background/fill color. Looking through different discussions, I've managed to piece together this:

var vcolor = event.value; 

if (vcolor == "Urgent Intervention") { 

    this.getField('Dropdown5').fillColor = color.red; 

}

else if (vcolor == "Intervention") { 

    this.getField('Dropdown5').fillColor = color.yellow; 

}

else if (vcolor == "On Watch") { 

    this.getField('Dropdown5').fillColor = color.blue; 

}

else if (vcolor == "At/Above Benchmark") { 

    this.getField('Dropdown5').fillColor = color.green; 

}

else if (vcolor == "n/a") { 

    this.getField('Dropdown5').fillColor = color.white; 

}

It appears to work how I intended it to, but I'm not sure if that's the best way to go about it. Without having any background on scripts, I just got lucky.

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 ,
Jan 12, 2016 Jan 12, 2016

Is that script a custom validation script of the Dropdown5 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
Guest
Jan 12, 2016 Jan 12, 2016

Yes, Dropdown5 is the name of the field that I'm experimenting on, and that's a script I pieced together for Validation.

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 ,
Jan 12, 2016 Jan 12, 2016
LATEST

In that case, change the lines of code like this:

   this.getField('Dropdown5').fillColor = color.red;


to this:


   event.target.fillColor = color.red;

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