Do I need to create a custom field first in the object ?

If yes, lets say I have created a custom field Active__c so following will be my VF page code ?

<apex:inputCheckbox value="{!Active__c}"/>

  • 1
    With a standard controller it would be <apex:inputCheckbox value="{!MyCustomObject.Active__c}"/> or with a custom controller <apex:inputCheckbox value="{!myCustomObjectPropertyName.Active__c}"/>.
    – Keith C
    Commented Nov 7, 2014 at 20:15
  • 1
    apex:inputCheckBox need not be bound to a custom field of type Checkbox - you can bind to a controller Boolean variable with a public getter/setter
    – cropredy
    Commented Nov 7, 2014 at 20:52

1 Answer 1


Depends on where you are checking state. If on the page you can use Javascript / jQuery

    <apex:inputCheckbox value="{!Active__c}" id="my_chk_bx" onchange="is_checked();"/>

function is_checked(){    
     var is checked = $('[id$=my_chk_bx]').prop('checked',true); 

will get you the stated of the checkbox.

If you are doing it in the controller, you can add an

<apex:actionSupport event="onchange" ..... />

to the checkbox to call a method in the controller to check the state and do what you need.

To do what you asked in your comment below something like:

<apex:inputCheckbox value="{!Active__c}" id="my_chk_bx" >
   <apex:actionSupport event="onchange" rerender="txt_panel"/>
 <apex:outPutPanel id="txt_panel" layout="inline">
     <apex:outPutText value="{!IF(Active__c,'Approved','Not Approved')}"/>
  • thank u for the reply. so lets say I am doing it on the page level, and if the user clicks on check...I want to display a text besides the checkbox saying Approved and by default when it is not checked I want it to show Not Approved. Is this possible ?
    – LazyBones
    Commented Nov 7, 2014 at 20:56
  • @sus - See updated answer
    – Eric
    Commented Nov 7, 2014 at 23:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .