Conditional Field Backrounds

Hi,
I know this is probally a simple one, but I would like to change the backround colour of fields in list view. I have used the following code successfully to change text colors, but backround colours would be better.

var c = '#00000' // black
if (myImportantField == myCriteria )
{
   c = '#FF000'; // red
}
return '<html><font color="' + c + '">' + myImportantValue + '</font></html>';

Place that in a calculation and use a label or field with displayType set to HTML_AREA to display this and you are set.

Do I just change ‘font color’ to ‘bgcolor’ ???

Hi Phil,

For background colors use table definitions like this:

return '<html><table width="100%"><tr bgcolor="' + c + '"><td>' + myImportantValue + '</td></tr><table></html>';

And in some situations you might want to set the height property of the TD tag as well.

Hope this helps.

Hi Robert,
Many thanks that works a treat, if I do not want to include the “myImportantValue” how do I take this out ? In other words I do not want to show any text at all. Just the coloured feild.

prj311:
Hi Robert,
Many thanks that works a treat, if I do not want to include the “myImportantValue” how do I take this out ? In other words I do not want to show any text at all. Just the coloured feild.

Use the HTML placemark " " instead of "myImportantValue to render an empty table cell.

Indeed the Non-Breaking Space ( ) will do the trick.

Hi Guys,
Sorry to be a pain, but how do I implement, is this correct

return '<html><table width="100%"><tr bgcolor="' + c + '">" "<td></td></tr><table></html>';

I am a little unsure

prj311:
Hi Guys,
Sorry to be a pain, but how do I implement, is this correct

return '<html><table width="100%"><tr bgcolor="' + c + '">" "<td></td></tr><table></html>';

I am a little unsure

Put " " inside the tags without the quotes like this:

return '<html><table width="100%"><tr bgcolor="' + c + '"><td> </td></tr><table></html>';

Many Thanks for your help, all works fine.

Hi,
Could I ask how to set the TD height as well, as the shape of my coloured boxes seem to be changing height when I select the record or click on them. Once again thank you in advance

And in some situations you might want to set the height property of the TD tag as well.

prj311:
Hi,
Could I ask how to set the TD height as well, as the shape of my coloured boxes seem to be changing height when I select the record or click on them. Once again thank you in advance

And in some situations you might want to set the height property of the TD tag as well.

The height can be set using the “height” property like this

return '<html><table width="100%"><tr bgcolor="' + c + '"><td height="25"> </td></tr><table></html>'; 

Find more info here.