+ Start a Discussion
uday kumar yuday kumar y 

How to hide the Permanent Address in the below code

<apex:page controller="Address">
<apex:form >
<apex:pageBlock >
    <apex:pageBlockSection >
        <apex:inputText value="{!Name}" label="Name"/>
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Temporary Address">
        <apex:inputText value="{!City}" label="City"/>
        <apex:inputText value="{!Address}" label="Address"/>
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Addresscheck">
        <apex:inputCheckbox value="{!Addresscheck}" label="Addresscheck"/>
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Permanent Address">
        <apex:inputText value="{!City1}" label="City1"/>
        <apex:inputText value="{!Address1}" label="Address1"/>
    </apex:pageBlockSection>
    <apex:pageBlockButtons >
        <apex:commandButton value="save" action="{!saverecords}"/>
    </apex:pageBlockButtons>
</apex:pageBlock>
</apex:form> 
</apex:page>

public class Address{
    public string Name{set;get;}
    public string City{set;get;}
    public string Address{set;get;}
    public string City1{set;get;}
    public string Address1{set;get;}
    public boolean Addresscheck{set;get;}
   
    
  
    
    public pageReference saverecords(){
    pageReference pref = null;
    Address__c ad = new Address__c();  
      if(Addresscheck == True){  
        ad.Name = Name;
        ad.City__c = City;
        ad.Address__c = Address;
        ad.City1__c = City;
        ad.Address1__c = Address;   
        }
      else{
        ad.Name = Name;
        ad.City__c = City;
        ad.Address__c = Address;
        ad.City1__c = City1;
        ad.Address1__c = Address1;   
      } 
      insert ad;  
      pref = new pageReference('/'+ad.Id);
      return pref;
    }  
 
}


Click the inputcheckbox automatically hide the Permanent Address pageblocksection?
Hemant_SoniHemant_Soni
Hi uday kumar,

Try Below Code 
i use javascript to hide your section.
 
<apex:page controller="Address" id="pgController">
<apex:form id="frm">
<script type="text/javascript">
function hideOnclick(){
var Addresscheck = document.getElementById("pgController:frm:pb:pbSection3:AddCheck").checked;
if(Addresscheck == true){
document.getElementById('pgController:frm:pb:pbSection4').style.display="none";
}
else{
document.getElementById('pgController:frm:pb:pbSection4').style.display="block";
}
}
</script>
<apex:pageBlock id="pb">

    <apex:pageBlockSection id="pbSection1">
        <apex:inputText value="{!Name}" label="Name"/>
    </apex:pageBlockSection>
    
    <apex:pageBlockSection title="Temporary Address" id="pbSection2">
        <apex:inputText value="{!City}" label="City"/>
        <apex:inputText value="{!Address}" label="Address"/>
    </apex:pageBlockSection>
    
    <apex:pageBlockSection title="Addresscheck" id="pbSection3">
        <apex:inputCheckbox value="{!Addresscheck}" label="Addresscheck" id="AddCheck" onclick="hideOnclick();"/>
    </apex:pageBlockSection>
    
    <apex:pageBlockSection title="Permanent Address" id="pbSection4">
        <apex:inputText value="{!City1}" label="City1"/>
        <apex:inputText value="{!Address1}" label="Address1"/>
    </apex:pageBlockSection>
  
   <apex:pageBlockButtons >
        <apex:commandButton value="save" action="{!saverecords}"/>
    </apex:pageBlockButtons>
    
</apex:pageBlock>
</apex:form> 
</apex:page>
I think this may help you

Thanks
Hemant
 
vijayabhaskarareddyvijayabhaskarareddy
Hi uday
try this.....
<apex:page controller="Address">
<apex:form >
<apex:pageBlock id="pg" >
    <apex:pageBlockSection >
        <apex:inputText value="{!Name}" label="Name"/>
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Temporary Address">
        <apex:inputText value="{!City}" label="City"/>
        <apex:inputText value="{!Address}" label="Address"/>
    </apex:pageBlockSection>
    <apex:pageblockSection columns="1" title="Addresscheck"  >
        <apex:pageblocksectionItem >
            <apex:inputCheckbox value="{!Addresscheck}">
                <apex:actionSupport event="onchange" action="{!check}" reRender="pg"/>
            </apex:inputCheckbox>
    </apex:pageblocksectionItem>
                       
    </apex:pageblockSection>    
    <apex:pageBlockSection title="Permanent Address" rendered="{!pbs2}" id="pg">
        <apex:inputText value="{!City1}" label="City1"/>
        <apex:inputText value="{!Address1}" label="Address1"/>
    </apex:pageBlockSection>
    <apex:pageBlockButtons >
        <apex:commandButton value="save" action="{!saverecords}"/>
    </apex:pageBlockButtons>
</apex:pageBlock>
</apex:form> 
</apex:page>
 
public class Address{

    
    public string Name{set;get;}
    public string City{set;get;}
    public string Address{set;get;}
    public string City1{set;get;}
    public string Address1{set;get;}
    public boolean Addresscheck{set;get;}
   
    public Boolean pbs2 {get;set;} 
     public Boolean pbs1cb1{get;set;} 
   
    public Address()
    {
      
        pbs2 =true;
    }
  
    
    public pageReference saverecords(){
    pageReference pref = null;
    Address__c ad = new Address__c();  
      if(Addresscheck == True){  
        ad.Name = Name;
        ad.City__c = City;
        ad.Address__c = Address;
        ad.City1__c = City;
        ad.Address1__c = Address;   
        }
      else{
        ad.Name = Name;
        ad.City__c = City;
        ad.Address__c = Address;
        ad.City1__c = City1;
        ad.Address1__c = Address1;   
      } 
      insert ad;  
      pref = new pageReference('/'+ad.Id);
      return pref;
    }  
     public void check()
    {
        if( Addresscheck== true )
        {
            pbs2 = false;
        }
        else{
        pbs2 = true;
        }
        }
 
}

Regards,
vijay
kindaly mark as best answer if it help you​