Make field color base on the option selected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2022 03:27 PM
Please I have a requirement to create a field on Requested item table thus;
"Project health" with choice with colors
i. On Tract ----- green
ii. At Risk -------yellow
iii. Off track-----red.
Please I need client script code for this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2022 07:36 PM
Hi,
Is this on Requested Item list view or on a form? If the question is on list, should use UI Policy instead of Client Script.
Also, is the question about showing selection choices have different color or changing color of a field based on a selection.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2022 09:06 AM
Hi Hitoshi,
The color will show on the form.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2022 10:36 PM
Hi,
Still not sure of the requirement.
If the requirement is to change field's background color based on selection, following script will do.
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
var field = g_form.getControl('project_health'); // name of choice field
if (newValue == 'on track') {
field.style.backgroundColor = "green";
} else if (newValue == 'at risk') {
field.style.backgroundColor = 'yellow';
} else if (newValue == 'off track') {
field.style.backgroundColor = 'red';
}
}
Sample output:
Case1: On track
Case 2:
Case3:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 01:03 PM
The code did not working. anything else to do?