- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2026 07:04 AM
I want to change the background color of single line text field for a catalog item on ServicePortal when user is trying to submit a form.
Basically it should work on an onChange of other field. the field I want to change is just a single line text and Presetted value in it. it will be visible based on the other field.
I tried Isolated script true and false and also tried g_form.setStyle and getControl nothing worked.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2026 03:43 AM
Hello @CharanKulukuri ,
Modify and add these lines of code as per requirement
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var title=this.document.getElementById("sp_formfield_text");
if(newValue=="1")
{
title.style.backgroundColor="blue";
}
else
{
title.style.backgroundColor="red";
}
}
// here Element ID is "sp_formfield_+VariableName".
//Prefix "sp_formfield_" is concatenated
//if variable name is subnet_retrieved then element ID is "sp_formfield_subnet_retrieved"
As mentioned by @Ankur Bawiskar DOM manipulation can cause scripts to break or generate unexpected errors especially after platform upgrades.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2026 03:43 AM
Hello @CharanKulukuri ,
Modify and add these lines of code as per requirement
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var title=this.document.getElementById("sp_formfield_text");
if(newValue=="1")
{
title.style.backgroundColor="blue";
}
else
{
title.style.backgroundColor="red";
}
}
// here Element ID is "sp_formfield_+VariableName".
//Prefix "sp_formfield_" is concatenated
//if variable name is subnet_retrieved then element ID is "sp_formfield_subnet_retrieved"
As mentioned by @Ankur Bawiskar DOM manipulation can cause scripts to break or generate unexpected errors especially after platform upgrades.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2026 03:51 AM
Hi @Rakesh_M ,
This kind of worked but the colour changed for field lable but not for value.
Is there a way I can change to for field value rather than field name?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2026 04:04 AM
Hi @CharanKulukuri ,
Please inspect the page and identify the correct element ID for the input field, then update your script to target that element instead.
