Make field color base on the option selected

johnsony2
Tera Contributor

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.

7 REPLIES 7

Hitoshi Ozawa
Giga Sage
Giga Sage

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.

Hi Hitoshi,

 

The color will show on the form.

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

find_real_file.png

Case 2: 

find_real_file.png

Case3:

find_real_file.png

The code did not working. anything else to do?