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
Fajer NaqeebFajer Naqeeb 

how to hide or show custom fields upon conditions

Khan AnasKhan Anas (Salesforce Developers) 
Hi Fajer,

Greetings to you!

Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page standardController="Contact" extensions="HideSectionBasedOnPicklistC">
    <apex:form >
        <apex:pageBlock > 
            <apex:actionRegion >
                <apex:selectList value="{!pickchoice}" multiselect="false" size="1">
                    <apex:selectOptions value="{!items}"/>
                    <apex:actionSupport event="onchange" rerender="out1,out2"/>
                </apex:selectList>
            </apex:actionRegion>            
            <br/><br/>
            <apex:pageBlockSection id="out1" >
                <apex:outputPanel rendered="{!IF(pickchoice== 'NRI' && pickchoice!= 'None', true , false)}">                    
                    <apex:outputLabel value="First Name" /><br/>
                    <apex:inputField value="{!contact.FirstName}" /><br/><br/>
                    <apex:outputLabel value="Last Name" /><br/>
                    <apex:inputField value="{!contact.LastName}" />
                </apex:outputPanel>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection id="out2" >
                <apex:outputPanel rendered="{!IF(pickchoice== 'Non-NRI' && pickchoice!= 'None', true , false)}">
                    <apex:outputLabel value="Email" /><br/>
                    <apex:inputField value="{!contact.Email}" /><br/><br/>
                    <apex:outputLabel value="Phone" /><br/>
                    <apex:inputField value="{!contact.Phone}" />
                </apex:outputPanel>
            </apex:pageBlockSection>        
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class HideSectionBasedOnPicklistC {
    
    public String Pickchoice {get;set;}
    
     public HideSectionBasedOnPicklistC(ApexPages.StandardController controller) {

    }
    
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('None','None'));
        options.add(new SelectOption('NRI','NRI'));
        options.add(new SelectOption('Non-NRI','Non-NRI'));
        return options;
    }
}


Or you can use the below code also:
<apex:page standardController="Account">
    
    <apex:form id="theForm">
        
        <apex:pageBlock>
            <apex:pageblockSection>
                <apex:inputField value="{!Account.Rating}">
                    <apex:actionSupport event="onchange" reRender="theForm"/>
                </apex:inputField>
            </apex:pageblockSection>
        </apex:pageBlock>
        
        <apex:pageblock>
            <apex:pageblockSection rendered="{!Account.Rating = 'Hot'}">
                <apex:inputField value="{!Account.Name}"/>
            </apex:pageblockSection>
            
             <apex:pageblockSection rendered="{!Account.Rating = 'Warm'}">
                <apex:inputField value="{!Account.Phone}"/>
            </apex:pageblockSection>
            
            <apex:pageblockSection rendered="{!Account.Rating = 'Cold'}">
                <apex:inputField value="{!Account.Website}"/>
            </apex:pageblockSection>
        </apex:pageblock>
        
    </apex:form>
    
</apex:page>

Please refer to the below link which might help you further.

https://success.salesforce.com/answers?id=9063A000000pYEyQAM

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Fajer NaqeebFajer Naqeeb
but i am not using picklist i am using check box checkbox value is 1 then other field under account should disable /hide 
Fajer NaqeebFajer Naqeeb
and when i am trying to chenge from Account.rating to account.Prospect i am recieving error : Error: Could not resolve field 'Prospect' from <apex:inputField> value binding '{!Account.Prospect}' in page custom
Khan AnasKhan Anas (Salesforce Developers) 
Please try this code:
<apex:page standardController="Account">
    
    <apex:form id="theForm">
        
        <apex:pageBlock >
            <apex:pageblockSection >
                <!-- Cb__c is checkbox field API name -->
                <apex:inputField value="{!Account.Cb__c}">
                    <apex:actionSupport event="onchange" reRender="theForm"/>
                </apex:inputField>
            </apex:pageblockSection>
        </apex:pageBlock>
        
        <apex:pageblock >
            <apex:pageblockSection rendered="{!Account.Cb__c = true}">
                <apex:inputField value="{!Account.Website}"/>
            </apex:pageblockSection>
            
            <apex:pageblockSection rendered="{!Account.Cb__c = false}">
                <apex:inputField value="{!Account.Phone}"/>
            </apex:pageblockSection>

        </apex:pageblock>        
    </apex:form>
</apex:page>

 
Fajer NaqeebFajer Naqeeb
thankyou code worked for me but it is not rendering to page which has my other fields other fields of page layout 
Fajer NaqeebFajer Naqeeb
Last resolution MR. Khan can you provide me please 
Fajer NaqeebFajer Naqeeb
why is it showing only three fields under account section after writing this code