How to display a custom button when checkbox is checked in Salesforce?

Sample code:

Visualforce page:

<apex:page controller="Sample" >
<apex:form >
    <apex:pageBlock id="pg" >
        <apex:pageblockSection >
            <apex:pageblockSectionItem >Check it to view the button:</apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:inputCheckbox value="{!option}" >
                    <apex:actionsupport event="onclick" action="{!change}" reRender="pg"/>
                </apex:inputCheckbox>               
            </apex:pageblockSectionItem>           
        </apex:pageblockSection>
        <apex:pageBlockButtons location="bottom">
            <apex:commandButton value="Submit" rendered="{!bool}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>   
</apex:page>


Apex Controller:

public class Sample
{
    public Boolean option {get;set;}
    public Boolean bool {get;set;}
   
    public Sample()
    {
         bool = false;
    }
    public void change()
    {
        if(option == true)
        {
            bool = true;
        }
        else
        {
            bool = false;
        }
    }
}


Output:



3 comments:

  1. when we use actionSupport,ActionFunction,ActionStatus in salesforce

    ReplyDelete
    Replies
    1. http://infallibletechie.blogspot.in/2012/12/apexactionstatus.html

      http://infallibletechie.blogspot.in/2012/12/rerender-based-on-selectlist-option.html

      http://infallibletechie.blogspot.in/2012/10/calling-controller-method-using.html

      Delete