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
Arpit Gupta 40Arpit Gupta 40 

How can i achieve Text Field dependent on Picklist field using VF page?

I have a Visual force page in which I have a custom picklist and custom text field. I want that text field become dependent upon selecting one value from picklist using VF page.
Best Answer chosen by Arpit Gupta 40
Arpit Gupta 40Arpit Gupta 40
I think i found my answer with this vf code:-
<apex:page standardController="Account" sidebar="false">
<apex:form >
<apex:pageBlock >
   <apex:pagemessages />
   <apex:pageBlockSection id="pm" columns="1" title="Dependent Text">
        <!-- Your picklist Field -->
        <apex:inputField value="{!Account.Status__c}">
        <apex:actionSupport event="onchange" rerender="pm"  status="status"/>
        </apex:inputField>
        <apex:panelGrid id="stdterm" rendered="{!Account.Status__c=='Other'}" >
        <!-- Comment text field appear when picklist value= 'Other' -->
        <apex:outputText >Comments &nbsp;&nbsp;&nbsp;&nbsp;<apex:inputField value="{!Account.Comments__c}"/></apex:outputText>
        </apex:panelGrid>
   </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>

All Answers

DeveloperSudDeveloperSud
Hi,

Try Something like this .Hope this will help.Commnet if need more help.If you find this helpful ,don't forget to mark it as solved.
 
<apex:page controller="prac1" >

<apex:form id="f" >
<apex:pageBlock >
<!-- Your picklist field -->
 <apex:selectList size="1" value="{!selVal}" >
  <apex:actionsupport event="onchange" action="{!conMethod}" reRender="f" /> 
  <apex:selectOptions value="{!options}" />
 </apex:selectList> <br/> 
 <!-- your dependent Text Field -->
 <apex:outputLabel value="Your Selected Value is :"/>
 <apex:outputText value="{!showPickVal}" >
 </apex:outputText>
</apex:pageBlock>
</apex:form>

</apex:page>
 
public with sharing class prac1 {

   
    public List<SelectOption> options{get;set;}
    public String selVal{get;set;}
    public String showPickVal{get;set;}

    public prac1(){
   
    options= new List<selectOption>();
    options.add(new selectoption('None','NONE'));
    options.add(new selectoption('test1','TEST1'));
    options.add(new selectoption('test2','TEST2'));
    
    
    }
    
    public pageReference conMethod(){
    showPickVal=selVal;
    return null;
    
    }
    
  
   
   
}

 
vikas rathi91vikas rathi91

Hello Arpit,

Without  see the code its difficult to give the answer.

 as you mention above you can use javascript to solve this problem. if posible past you code here then We will be help you better.

thanks

Arpit Gupta 40Arpit Gupta 40

Hi @DeveloperSud , @VikasRathi91

I have a vf page on Account. there are two custom field. One custom picklist field is "Status"  and one text field is "Comment". If i choose status "Others" text field enable for editing otherwise text field greyed out(not writable).

Arpit Gupta 40Arpit Gupta 40
I think i found my answer with this vf code:-
<apex:page standardController="Account" sidebar="false">
<apex:form >
<apex:pageBlock >
   <apex:pagemessages />
   <apex:pageBlockSection id="pm" columns="1" title="Dependent Text">
        <!-- Your picklist Field -->
        <apex:inputField value="{!Account.Status__c}">
        <apex:actionSupport event="onchange" rerender="pm"  status="status"/>
        </apex:inputField>
        <apex:panelGrid id="stdterm" rendered="{!Account.Status__c=='Other'}" >
        <!-- Comment text field appear when picklist value= 'Other' -->
        <apex:outputText >Comments &nbsp;&nbsp;&nbsp;&nbsp;<apex:inputField value="{!Account.Comments__c}"/></apex:outputText>
        </apex:panelGrid>
   </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>
This was selected as the best answer