set backgroundcolor of a field depending on a value

I want the background color of a field blue when the value of that field is 1. If the field has a different value the color must be white.
I can set the background color on the onDataChange event and on the onRecordSelection event (so the background is blue when a previous or next record is displayed).

Can I set the background color in an easier way? With a calculated field for instance?

This is a calculated field we use to display staff efficiency in four colours depending on % of target achieved.

var vHTML = null;
var vPCachv = billhrs_pcach_mth_c


if (vPCachv > 1)
{
	if (vPCachv <70)					var vBG = '#ff0000';	
	if (vPCachv >69 && vPCachv < 100)	var vBG = '#ff6633';
	if (vPCachv >99 && vPCachv < 130)	var vBG = '#009933';
	if (vPCachv >129 )					var vBG = '#990099';


	var vFG		= '#ffffff'	

	var vHTML    = '<html><body> <div align="center"> <table border="0" width=70><tr bgcolor="' + vBG + '" >'   
	vHTML 		+= '<td height="25" valign="bottom" align="center"> <font size="3" face="Verdana"  color="' + vFG + '">'; 
	vHTML		+= utils.numberFormat(vPCachv, '###') + '</font></td></tr><table></div></body></html>'; 
}

return vHTML;

Set the field on your layout as ‘HTML_AREA’ and remember to tick 'displaysTags

Hope this a useful starting point for you

It helped me very much! Thank you

You’re welcome.

All the clever bits will probably have come from a David Workman post - well worth checking out http://www.servoymagazine.com/ for more.

Regards

Graham