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
TechSteveTechSteve 

Check box custom field data on visualforce page

 

I have a table on a visualforce page embedded in a standard view and I want to change the colour of its background dependent on the check box which is on the standard page.
I basically need to have a view open which when a check box is ticked a square turns red.
The only way i could think of doing it was as above but i cannot get the value of a custom field (the check box) to be read on the visualforce page. I can display a standard field values onto the page no problem with <apex:outputField value="{!Contact.name}"/> but not the custom fields.
If you have an easier way to achieve this effect please let me know or how to get the boolean value onto my page that will do just as well.

Thank you

Steve

A very new developer.

 



Best Answer chosen by Admin (Salesforce Developers) 
TechSteveTechSteve

Thanks. found a way around my problem with a little javascript! this gave me a field that changes according to the contact type check box and then the DNR check box changes the background color.

  <script type="text/javascript">
        if ({!contact.Is_Client__c})
        {
            if ({!contact.DNR_Authorisation_Uploaded__c})
            {
                document.write("<div style=background-color:#ff0000><h1><center>DNR</center></h1></div>");
            }
            else
            {
                document.write("<center>CPR</center>");
            }
        }
    </script>         

All Answers

FromCRMWonderlandFromCRMWonderland

You can develope inline vf page. But the only point is that the same vf page will be displayed only on the standard detail page of your record.

 

You can fire query to fetch the value of checkbox field in your record. Then you can decide the background of the table.

 

TechSteveTechSteve

Thanks for your suggestion. That is what i am trying to do. The problem is I cant find out how to fire the query that gets the check box value, Thats where I am struggling. Any help would be appreciated.

Rehan DawtRehan Dawt

Hi,

 

You can do one thing. Try out defining the string in the Apex class and set that string to the Check box and call the function in the Action support of the Check box event as KeyPress or onClick. nad set that string value to Field you want

 

Or

 

You can use the JavaScript. where you can fetch the value by Id and Set that Check box color the which ever you want the fields Color to be change.

 

Following is  one approach but i am not able to assign that thing to Apex page. just have look on it.

 

Apex Class :

 

public String strColor {get;set;}

public String blnColor {get;set;}

 

public Constructor()

{

        strColor = white; // ascii value

}

 

Public void setColor()

{

       strColor = blnColor;

}

 

Page Class:

 

<apex:outputField value="{!Account.Name}" > // assign the blnColor color over here

 

<apex:outputField value="{!Account.Checkbox}" >  // set the strColor  color over here

            <actionsupport event="OnClick" action="{!setColor}" />

</apex:outputField>

 

TechSteveTechSteve

Thanks. found a way around my problem with a little javascript! this gave me a field that changes according to the contact type check box and then the DNR check box changes the background color.

  <script type="text/javascript">
        if ({!contact.Is_Client__c})
        {
            if ({!contact.DNR_Authorisation_Uploaded__c})
            {
                document.write("<div style=background-color:#ff0000><h1><center>DNR</center></h1></div>");
            }
            else
            {
                document.write("<center>CPR</center>");
            }
        }
    </script>         

This was selected as the best answer
Suma GangaSuma Ganga
HI,

i tried with the above code:
<script type="text/javascript">
        if ({!contact.Is_Client__c})
        { .....}
     
but i am gettting error like below:
         
SyntaxError: invalid property id

if ({!Account.Custom_Check_box__c}){

i have a custom checkbox  on my account detail page, i have to perform sme operation using Javascript when checkbox is checked..

pls help..