+ Start a Discussion

How to display based on dropdown selected?

I have one dropdown with values"text,radio,multiselect,numeric".
My question is when I select text from dropdown  I should get text and when radio selected radio button should appear.How can i achieve this?
v varaprasadv varaprasad
Hi Prashanth,

Please find sample code below : 
<apex:page controller="PicklistOptons" >
    <apex:form >
        <apex:pageBlock title="All Option">
            <apex:selectList value="{!Selected}" multiselect="false" size="1" onclick="">
                Select :  <apex:selectOptions value="{!options}" >                     
                <apex:actionSupport event="onchange"  reRender="pg1"/>
        <apex:pageBlock title="Display Results" id="pg1">
          <apex:pageBlockSection title="Display Text field" rendered="{!IF(Selected = 'Text', true, false)}">
                <apex:pageBlockSectionItem >
                    EnterName = <apex:inputText />
            <apex:pageBlockSection title="Display Radio button" rendered="{!IF(Selected = 'Radio', true, false)}" >
                <apex:selectRadio >                   
                        <apex:selectOption itemLabel="Radio1" itemValue="Radio1"></apex:selectOption>                    


public class PicklistOptons {
    public list<SelectOption> options{get;set;}
    public string Selected{get;set;}   
    public PicklistOptons(){
        options = new list<SelectOption>();
        options.add(new SelectOption('None','None'));
        options.add(new SelectOption('Text','Text'));  
        options.add(new SelectOption('Radio','Radio')); 

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

@For  Support: varaprasad4sfdc@gmail.com

Glyn Anderson (Slalom)Glyn Anderson (Slalom)
Varaprasad has the solution.  One small optimization, though:
<apex:pageBlockSection title="Display Text field" rendered="{!selected=='Text'}">

And similarly for the 'Radio' pageBlockSection.  Happy coding!
Thanks VaraPrasad for your reply.But my requirement is whenever I click 'Text'  from dropdown it should display textbox  in below Picklist value and when I click 'Radio' from dropdown it should display Radiobutton in PickList value shown in screenshot.
Please have a look at screenshotUser-added image

Below is my code
public class QuestionAddRow
 public List<Answer__c> memberList {get;set;}  
   public List<Answer__c> memberAddList {get;set;}   
  public String memberName {get;set;}           
 public QuestionAddRow(ApexPages.StandardController sc)   
    String sql = 'SELECT Id, Name FROM Answer__c';        
 memberList = Database.Query(sql);        
 memberAddList = new List<Answer__c>();     
    memberAddList.add(new Answer__c());  
    public void AddRow()   
 memberAddList.add(new Answer__c());     }  }

VF Page:
<apex:page sidebar="false" standardController="Answer__c" extensions="QuestionAddRow" >
<apex:form >
<apex:pageBlock id="membAdd" >
<apex:pageblockSection >
<apex:pageBlockTable value="{!memberAddList}" var="memb">
<apex:column headerValue="Question"> <apex:inputField value="{!memb.Name}"/>
</apex:column> <apex:column headerValue="Type">
<apex:inputField value="{!memb.Type__c}" />
<apex:actionSupport event="onchange" reRender="acs"/>
</apex:column> <apex:column headerValue="Picklist Value" >
<apex:inputText title="Radio Value" rendered="{!IF(memb.Type__c= 'Radio', true, false)}"/>
<br/><apex:commandLink value="Add Question" action="{!addRow}" reRender="membAdd"/>
<apex:pageblockSection columns="1">
<apex:pageblockSectionItem >
<apex:commandButton value="Save"/>
<apex:commandButton value="Cancel"/>