+ Start a Discussion
paddupaddu 

urgent help: Using actionSupport

Hi,

 

How to display a text filed dynomically when selecting a Picklist option on a VF page. For example picklist values are val1, val2 & val3, i want to display a text field only when selecting val3. I think it could be done by using actionSupport & reRender, but I never worked on actionSupport,  can any one help me how to achieve this throught actionSupport or any other approach ?.

Any help must be highly appreacted.

 

 

Thanks in advance!

Best Answer chosen by Admin (Salesforce Developers) 
yvk431yvk431

if you are not that familiar with apex please use the below :

 

<apex:pageBlock id="theBlock">
   <apex:inputCheckbox value="{!theSObject.CheckBox__c}">
      <apex:actionSupport event="onchange" rerender="theBlock"/>
   </apex:inputCheckbox>

   <apex:inputText value="{!theSObject.TextField__c}" disabled="false" rendered="{!(theSObject.CheckBox__c == true)}"/>
   <apex:inputText value="{!theSObject.TextField__c}" disabled="true" rendered="{!(theSObject.CheckBox__c != true)}"/>

   <!-- Or to simply have a field that appears only when the box is checked -->
   <apex:inputText value="{!theSObject.TextField__c}" rendered="{!(theSObject.CheckBox__c == true)}"/>
</apex:pageBlock>

replace the checkbox field with your picklist, if needed assign the values using a formula

 

--yvk

All Answers

yvk431yvk431

if you are using input field

<page id="pg" standardcontroller="object" extensions="controller">

<apex:form id+"frm">

<apex:pageBlock id="pgb">

<apex:outputPanel id="outpnl">

<apex:pageBlockSection id = "pgbs" columns="1">
            
              <apex:pageBlockSectionItem id="pbsipck">
                  <apex:outputLabel value="picklist" />
                  <apex:actionRegion >
                    <apex:inputField value="{!object.picklistId}" id="pcknm">
                       <apex:actionSupport event="onchange"  action="{!pckChange}" rerender="pbstxtfld"/>  
                    </apex:inputField>     
                  </apex:actionRegion>  
               </apex:pageBlockSectionItem>

 

               <apex:inputField id="txtid" value="{!object.txtid}"/>

</apex:pageBlockSection>

</apex:outputPanel>

here in the action funciton you can have a void function and assign the value to the text field or instead of a action you can assign the value directly using javascript using actionFunction

<page id="pg" standardcontroller="object" extensions="controller">

<apex:form id+"frm">

<apex:actionFunction name="refreshtxt" rerender="txtid,pgbs"/>

<apex:pageBlock id="pgb">

<apex:outputPanel id="outpnl">

<apex:pageBlockSection id = "pgbs" columns="1">           
            
             
                
                    <apex:inputField value="{!object.picklistId}" id="pcknm" onchange="javascript&colon;updatetxt();"/>
                       <apex:inputField id="txtid" value="{!object.txtid}"/>

</apex:pageBlockSection>

</apex:outputPanel>

 

 

<script>

function updatetxt()

{

     var Pck = document.getElementById("pg:frm:pgb:pgbs:pcknm");

     if(Pck.options[Pck.selectedIndex].value == 'Some thing')

     document.getElementById("pg:frm:pgb:pgbs:txtid").value = 'some thing';

 

     refreshtxt();

    

}

</script>

 

paddupaddu

Hi,

 

Thanks you very much for your reply. It would be great if you can provide the sample controller class for the give VF page, i.e how to write  a action method {!pckChange} in controller.

 

 

 

Regards,

paddu

yvk431yvk431

if you are not that familiar with apex please use the below :

 

<apex:pageBlock id="theBlock">
   <apex:inputCheckbox value="{!theSObject.CheckBox__c}">
      <apex:actionSupport event="onchange" rerender="theBlock"/>
   </apex:inputCheckbox>

   <apex:inputText value="{!theSObject.TextField__c}" disabled="false" rendered="{!(theSObject.CheckBox__c == true)}"/>
   <apex:inputText value="{!theSObject.TextField__c}" disabled="true" rendered="{!(theSObject.CheckBox__c != true)}"/>

   <!-- Or to simply have a field that appears only when the box is checked -->
   <apex:inputText value="{!theSObject.TextField__c}" rendered="{!(theSObject.CheckBox__c == true)}"/>
</apex:pageBlock>

replace the checkbox field with your picklist, if needed assign the values using a formula

 

--yvk

This was selected as the best answer
paddupaddu

Thank you very much. Really appreciate your help...

 

 

Regards,

Paddu