The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Change the colour of a checkbox field.

Ramkumar Thanga
Mega Sage

Hello Experts,

 

I have a requirment to change the colour of a check box(True/False) type field, when the filed is checked.

If the check box is checked , the colour of the filed name and the check box should turn to 'red' colour. and it should turn back to black when it is unchecked.

Let me know, how to achieve this.

 

Thank you,

Ramkumar

3 REPLIES 3

Anurag Tripathi
Mega Patron
Mega Patron

Hi Ram,

 

Check this out:

 

https://www.w3schools.com/howto/howto_css_custom_checkbox.asp

-Anurag

Ramkumar Thanga
Mega Sage

Hi Anurag,

 

I was able to change the field label by using the below client script. But I want the check box (container) colour should also get changes when the check box got ticked.

 

Here, is the on change client script which changes the label colour.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var bsc = g_form.getValue('u_business_critical');
var incidentbsc = document.getElementById('label.incident.u_business_critical');
if (bsc == 'true'){
incidentbsc.style.color = "red";
}
else{
incidentbsc.style.color = "black";
}

}

 

** I want know how to change the check box container colour to red.

                 find_real_file.png

 

 

You can achieve this using Client Script:

g_form.getControl('checkbox').parentNode.style.color = 'red'

just as it was mentioned here:

https://community.servicenow.com/community?id=community_question&sys_id=c5f117eddbdcdbc01dcaf3231f96193d

 

REgards,

Sachin