function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rafael.Martins.SantosRafael.Martins.Santos 

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

Hi

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:

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

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

Best Regards
Rafael
Rahul KumarRahul Kumar (Salesforce Developers) 
SalesFORCE_enFORCErSalesFORCE_enFORCEr
You can do it like this:
<td style="IF(Status=='Value 1',background-color:Blue,background-color:Red)"></td>
Rafael.Martins.SantosRafael.Martins.Santos
Hi,
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?
 
SalesFORCE_enFORCErSalesFORCE_enFORCEr
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.
Rafael.Martins.SantosRafael.Martins.Santos
Ok I gonna try, thanks
Rafael.Martins.SantosRafael.Martins.Santos
Hi,
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.
SalesFORCE_enFORCErSalesFORCE_enFORCEr
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++){
if(status[i].value=='XYZ'){
status[i].style.backgroundColor = 'red';
}
}
}