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
vikramkkvikramkk 

Section ishould be displayed based on a picklist value.

In a visualforce page, I want to display a section (say with id - payment) only if a picklist value is selected in the following code. The section should not be displayed on load of page. it is to be displayed only if a particular picklist value is selected.

 

<apex:pageBlockSectionItem id="ReturnTypeItem">
                    <apex:outputLabel for="ReturnType">Return Type</apex:outputLabel>
                     <apex:inputField required="true" id="ReturnType" value="{!Case.Return_Type__c}"  />
</apex:pageBlockSectionItem>
Please help me on this. Many thanks.
Best Answer chosen by Admin (Salesforce Developers) 
Chamil MadusankaChamil Madusanka

Try this solution

 

<apex:page standardController="Case">
  
  <apex:form >
 
  <apex:inputField value="{!Case.Origin}">
      <apex:actionSupport event="onchange" reRender="sectionOne"/>
  </apex:inputField>
      <apex:pageBlock >
          <apex:pageBlockSection id="sectionOne">
              <apex:pageBlockSectionItem >
                  <apex:inputField value="{!Case.Reason}"/>
              </apex:pageBlockSectionItem>
              
              <apex:pageBlockSectionItem id="ReturnTypeItem" rendered="{!Case.Origin=='Phone'}">
                    <apex:outputLabel for="ReturnType">Return Type</apex:outputLabel>
                     <apex:inputField required="true" id="ReturnType" value="{!Case.Return_Type__c}"  /> 
              </apex:pageBlockSectionItem>
              
             
          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

All Answers

Chamil MadusankaChamil Madusanka

Try this solution

 

<apex:page standardController="Case">
  
  <apex:form >
 
  <apex:inputField value="{!Case.Origin}">
      <apex:actionSupport event="onchange" reRender="sectionOne"/>
  </apex:inputField>
      <apex:pageBlock >
          <apex:pageBlockSection id="sectionOne">
              <apex:pageBlockSectionItem >
                  <apex:inputField value="{!Case.Reason}"/>
              </apex:pageBlockSectionItem>
              
              <apex:pageBlockSectionItem id="ReturnTypeItem" rendered="{!Case.Origin=='Phone'}">
                    <apex:outputLabel for="ReturnType">Return Type</apex:outputLabel>
                     <apex:inputField required="true" id="ReturnType" value="{!Case.Return_Type__c}"  /> 
              </apex:pageBlockSectionItem>
              
             
          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

This was selected as the best answer
asish1989asish1989

Hi

 This is exactly what you wanted...

 

<apex:page standardController="Case">
 
  <apex:form >
  <apex:pageBlock >
 
 <b>Case Origin</b>: <apex:inputField id="CaseOrigin" value="{!Case.Origin}">
      <apex:actionSupport event="onchange"/>
  </apex:inputField><br/><br/>
      
          <apex:pageBlockSection id="sectionOne" rendered="{!Case.Origin=='Phone'}">
              <apex:pageBlockSectionItem >
                 Case Reason : <apex:inputField value="{!Case.Reason}"/>
              </apex:pageBlockSectionItem>
              
              <apex:pageBlockSectionItem id="ReturnTypeItem" >
                    <apex:outputLabel for="ReturnType">Return Type</apex:outputLabel>
                     <apex:inputField required="true" id="ReturnType" value="{!Case.Return_Type__c}"  />
              </apex:pageBlockSectionItem>
              
             
          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>

 

 

 

Did this post solve your error then please mark it solved...

 

Thanks

asish

 

 

 

vikramkkvikramkk

Thanks Chamil and Ashish. It worked.