+ Start a Discussion

How change a background of a visualforce page according of the value of the field?


I have a table that will have a status value. According of the value, the color of the background cell will change.
I want know how can I do that?
For example:

<td>Value 1</td>
<td>Value 2</td>

Value 1 must be the color blue
Value 2 must be the color red 

Best Regards
Rahul KumarRahul Kumar (Salesforce Developers) 
You can do it like this:
<td style="IF(Status=='Value 1',background-color:Blue,background-color:Red)"></td>
I have to use the tag <apex:repeat>, so the rows and collumns will be created by the repeat tag. How I can get the value of the field check if have determinated value and fill with the background color?
Do you all knows how to do that using javasscript?
In the repeat tag also, you must be using <td> so just add the IF condition based on the Status value and it will be good.
Ok I gonna try, thanks
It works.
But the code became too long.
Is it possible to do something like that:
            <td style="{!if(conta.ServiceNow_Status__c='Qualificar','background-color:#FFD700; font-weight: bold', 
         if(conta.ServiceNow_Status__c == 'Service','background-color:#4682B4; font-weight: bold', 
         if(conta.ServiceNow_Status__c == 'Concorrente','background-color:#CD0000; font-weight: bold', 
         if(conta.ServiceNow_Status__c == 'Com oportunidade','background-color:#9ACD32; font-weight: bold', 
         if(conta.ServiceNow_Status__c == 'Outro','background-color: #B5B5B5; font-weight: bold', 'background-color:#FFA500; font-weight:bold')))))}">{!conta.ServiceNow_Status__c}</td>

in javascript?

I have at least mores 20 <td> , so I can't do this in each tag.
In javascript, you can get the value by tag name, document.getElementByTagName('td').value and put if else based on Status and set the background color.
window.onload = function(){
var status = document.getElementByTagName('td');
for(var i=0;i<status.length;i++){
status[i].style.backgroundColor = 'red';