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
erikdozsaerikdozsa 

Populate apex outputText field after picklist change

Dear all,

 

Could you please give me some example for the following case?

 

I have a picklist and based on the picked value I am doing some calculation in the background. I would like to display the calculated result in an outputText field right after I picked the value from the picklist.

 

How could I do that?

 

Thank you so much,

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

Use action support with the select list of the picklist and in the action of the actionsupport call an apex method. In the apex method just assign the selected picklist value in the value of the output text like this.

 

Controller

public String strInOutputText{get;set;}

public String selectedPkVal{get;set;}

 

public void callApex(){

strInOutputText selectedPkVal;

}

 

Page

<apex:outputpanel id="Outputtext">

<apex:outputtext value="{!strInOutputText}"/>

</apex:outputpanel>

<apex:selectList value="{!selectedPkVal}">

<apex:actionsupport event="onchange" rerender="Outputtext" action="{!callApex}"/>

<apex:selectOption value="Your List Value"/>

</apex:selectList>

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

All Answers

souvik9086souvik9086

Use action support with the select list of the picklist and in the action of the actionsupport call an apex method. In the apex method just assign the selected picklist value in the value of the output text like this.

 

Controller

public String strInOutputText{get;set;}

public String selectedPkVal{get;set;}

 

public void callApex(){

strInOutputText selectedPkVal;

}

 

Page

<apex:outputpanel id="Outputtext">

<apex:outputtext value="{!strInOutputText}"/>

</apex:outputpanel>

<apex:selectList value="{!selectedPkVal}">

<apex:actionsupport event="onchange" rerender="Outputtext" action="{!callApex}"/>

<apex:selectOption value="Your List Value"/>

</apex:selectList>

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

This was selected as the best answer
erikdozsaerikdozsa

Hi, thanks so much, it is working fine now.

 

I have another question. I tried to add a label to the apex:outputtext like this:

 

<apex:outputtext value="{!strInOutputText}" label="User"/>

 

But the label did not show up. How could I do this?

 

Thanks,

souvik9086souvik9086

The syntax is correct. Make sure that you have value in the variable strInOutputText. Then only the label will be displayed in the left of the value.

 

If the post helps you please throw KUDOS.

Thanks