1

I am trying to toggle my pageblocksection on radiobutton but it is not working. I am sharing my code with you.

vf page

apex:page StandardController="DetailLog__c" extensions="detailctrl" sidebar="false">    
    <apex:form >
        <apex:selectRadio value="{!radiobtn}">
            <apex:selectOptions value="{!PageDetail}"/>
            <apex:actionSupport event="onChange" reRender="cpBlock"/>
        </apex:selectRadio>  
        <apex:pageBlock id="cpBlock" >
            <apex:pageblockSection title="Personal Detail" rendered="{!show}">
                <apex:outputField value="{!DetailLog__c.First_Name__c}"/>
                <apex:outputField value="{!DetailLog__c.Middle_Name__c}"/>
                <apex:outputField value="{!DetailLog__c.Last_Name__c}"/>
                <apex:outputField value="{!DetailLog__c.Date_of_Birth__c}"/>
                <apex:outputField value="{!DetailLog__c.Father_Name__c}"/>
                <apex:outputField value="{!DetailLog__c.Mother_Name__c}"/>
                <apex:outputField value="{!DetailLog__c.Permanent_Address__c}"/>
                <apex:outputField value="{!DetailLog__c.PAN_No__c}"/>
                <apex:outputField value="{!DetailLog__c.Mobile_Number__c}"/>                
            </apex:pageblockSection>                                                               
             <apex:pageblockSection title="Professional Detail" rendered="{!hide}">                
                <apex:outputField value="{!DetailLog__c.First_Name__c}"/>
                <apex:outputField value="{!DetailLog__c.Last_Name__c}"/>
                <apex:outputField value="{!DetailLog__c.Email_ID__c}"/>
                <apex:outputField value="{!DetailLog__c.Fax_Number__c}"/>
                <apex:outputField value="{!DetailLog__c.Office_Address__c}"/>
                <apex:outputField value="{!DetailLog__c.Passport_Number__c}"/>
                <apex:outputField value="{!DetailLog__c.Desgination__c}"/>
                <apex:outputField value="{!DetailLog__c.Age__c}"/>
            </apex:pageblockSection>
        </apex:pageBlock>    
    </apex:form>
/apex:page>

Controller Extension

public class detailctrl {
    public String radiobtn{get;set;}

    public Boolean show
    {   
        get{ return radiobtn == 'Option1';}
    }

    public Boolean hide
    {            
        get{ return radiobtn == 'Option2';}                                                            
    } 

    public List<SelectOption> getPageDetail()
    {        
        List<SelectOption> options=new List<SelectOption>();            
        options.add(new SelectOption('Option1','Personal Detail'));
        options.add(new SelectOption('Option2','Professional Detail'));
        return options;
    }

    public detailctrl(ApexPages.StandardController controller) {        
        radiobtn='Option2';      
    }    
}

1 Answer 1

1

I find two root cause for your solution not to be working.

  1. You are using onChange instead of onchange. Since Javascript is case sensitive it won't trigger the appropriate event.
  2. You are trying to use onchange along with radio button. Its better to use onclick over onchange. You can find the reason for this here.

Hope this helps.

0

You must log in to answer this question.

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