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
Kushal MishraKushal Mishra 

get field according to picklist values.

Hello guys,

Please help me, there is a picklist with three values(user,account,opportunity) and three field with same name. i want that when i select user picklist value then we would get user field and same thing should be happen for account and opprtunity picklist value and when picklist value none then there should be no any field is there. please help me.
MithunPMithunP
Hi Kushal Mishra,

If you want to implement it in VF Page,
Here is the sample code for your scenario, Create a VF page for below code and try to change Opportunity stage values to Prospecting, Closed Won and Closed Lost .
 
<apex:page standardController="Opportunity">
<apex:form id="form1">
<apex:pageBlock id="block1">
<apex:outputPanel >
<apex:pageBlockSection id="section1">
<apex:inputField value="{!Opportunity.StageName}" id="populate" >
<apex:actionSupport event="onchange" reRender="section2"/>
</apex:inputField>
</apex:pageBlockSection>

<apex:pageblockSection id="section2" >
<apex:inputField value="{!Opportunity.NextStep}" rendered="{!IF(Opportunity.StageName == 'Closed Won',true,false)}" id="textpop" />
<apex:inputField value="{!Opportunity.Amount}" rendered="{!IF(Opportunity.StageName == 'Prospecting',true,false)}" id="textpop2" />
<apex:inputField value="{!Opportunity.Type}" rendered="{!IF(Opportunity.StageName == 'Closed Lost',true,false)}" id="textpop4" />

</apex:pageblockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Best Regards,
Mithun.
 
Kushal MishraKushal Mishra
thanks a lot MithunP. but this code is not workinr for custome object.please tell me . i need to do some changes in this code for custome object and its field 
MithunPMithunP
Hi Kushal Mishra,

Ok, Assume that below are the your custom object details.

1. Custom object API name is "TestObj__C".
2. Custom Picklist field API name is "TestPicklict__C" and picklist values are (Opt1, Opt2 and Opt3).
3. Custom Text field API name is "Textfield11__C".
4. Custom Text field API name is "Textfield22__C".
5. Custom Text field API name is "Textfield33__C".

Now, we have one custom object (TestObj__C) and four custom fields (TestPicklict__C, Textfield11__C, Textfield22__C and Textfield33__C).

Here is updated code for above custom object.
 
<apex:page standardController="TestObj__C">
<apex:form id="form1">
<apex:pageBlock id="block1">
<apex:outputPanel >
<apex:pageBlockSection id="section1">
<apex:inputField value="{!TestObj__C.TestPicklict__C}" id="populate" >
<apex:actionSupport event="onchange" reRender="section2"/>
</apex:inputField>
</apex:pageBlockSection>

<apex:pageblockSection id="section2" >
<apex:inputField value="{!TestObj__C.Textfield11__C}" rendered="{!IF(TestObj__C.TestPicklict__C == 'Opt1',true,false)}" id="textpop" />
<apex:inputField value="{!TestObj__C.Textfield22__C}" rendered="{!IF(TestObj__C.TestPicklict__C == 'Opt2',true,false)}" id="textpop2" />
<apex:inputField value="{!TestObj__C.Textfield33__C}" rendered="{!IF(TestObj__C.TestPicklict__C == 'Opt3',true,false)}" id="textpop4" />

</apex:pageblockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Best Regards,
Mithun.
Kushal MishraKushal Mishra
hi mithun,
thanks for this, but if i want to take controller apart from standardController then how can we do this.
please have a look this code.it is not working.
====================================vf page=============================

<apex:page Controller="Controller1 ">
<apex:form id="form1">
<apex:pageBlock id="block1">
<apex:outputPanel >
<apex:pageBlockSection id="section1">
<apex:inputField value="{!groupAlert.StageName}" id="populate" > <apex:actionSupport event="onchange" reRender="section2"/> </apex:inputField>
</apex:pageBlockSection>
<apex:pageblockSection id="section2" >
<apex:inputField value="{!groupAlert.NextStep}" rendered="{!IF(groupAlert.StageName == 'Closed Won',true,false)}" id="textpop" /> <apex:inputField value="{!groupAlert.Amount}" rendered="{!IF(groupAlert.StageName == 'Prospecting',true,false)}" id="textpop2" /> <apex:inputField value="{!groupAlert.Type}" rendered="{!IF(groupAlert.StageName == 'Closed Lost',true,false)}" id="textpop4" /> </apex:pageblockSection>
</apex:outputPanel>
</apex:pageBlock> </apex:form> </apex:page>
=======================================Controller class=====
public with sharing class Controller1 {
public TestObj__C groupAlert{get;set;}

}
==========================================================
please help ASAP.