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
Abhishek RayAbhishek Ray 

Visualforce page : Snippet for showing/hiding a section in opportunity.

Hi, I need help. I have a picklist field in Opptunity object called 'Template" = Connect. So, whenever a user selects this picklist, a section called ="Proposal for Connect" will be visible other it will be hidden. How I can achieve it. Please help. I started with something but I am not going anywhere with it. Please help.


<apex:page standard controller="Opportunity" > <script> function doChange({!Opportunity.Template__c})

{     if({!Opportunity.Template__c} == 'Connect')

    {         document.getElementById('chk').style.visibility='Proposal Language for Intralinks Connect';     }     else     {         document.getElementById('chk').style.visibility="hidden"​';     }



       <apex:selectList value="#F3F3EC"  onchange="displaydiv(this.value)" size="1">

            <apex:selectOption itemValue="value1" itemLabel="value 1"/>

            <apex:selectOption itemValue="value2" itemLabel="value 2"/>

            <apex:selectOption itemValue="value3" itemLabel="value 3"/>



    <div id="chk" style="display:none;">






You can show/hide fields of an object based on the selection of picklist values of the object by giving a condition in the


render part. Keep the fields inside the pageBlockSection and embed the pageBlockSection inside outputPanel and


onchange of values of picklist reRender the outpanel which will check the value of the picklist selected and decides whether


it has to be render.






<apex:page standardController="Opportunity">
      <apex:form >
          <apex:pageBlock title="Enter Opportunity Information">
              <apex:pageBlockButtons location="bottom">
                  <apex:commandButton value="Save" action="{!Save}"/>
                  <apex:commandButton value="Cancel" action="{!Cancel}" immediate="true"/>                                
              <apex:PageblockSection columns="1" >
                      <apex:inputField value="{!Opportunity.Name}"/>
                     <apex:PageBlockSectionItem >
                         <apex:outputLabel value="Stage"/>
                         <apex:actionRegion >
                          <apex:inputField value="{!Opportunity.StageName}">
                          <apex:actionSupport event="onchange" reRender="ajaxrequest" />
              <apex:outputPanel id="ajaxrequest">   
                  <apex:pageBlockSection rendered="{!Opportunity.StageName=='Prospecting'}" >
                      <apex:inputField value="{!Opportunity.CloseDate}"/>



You can do the same using actionFunction and actionSupport if you have any complicated rendering criteria


Mark it solved if it solves your question