Skip to main content
January 13, 2016
Question

Script for Form Field Color Based on Specific Text

  • January 13, 2016
  • 1 reply
  • 400 views

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.

This topic has been closed for replies.

1 reply

Inspiring
January 13, 2016

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

January 13, 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.

Inspiring
January 13, 2016

Is that script a custom validation script of the Dropdown5 field?