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
MIDHUN G REDDYMIDHUN G REDDY 

How to add two picklist values and display in text box

Hi,
i have two picklists and one text box, Based on picklist values i want to display result value in textbox
Automatically
Any Help..

Thanks
Midhun
salesforce mesalesforce me
Hi check it once...
 
<apex:page controller="mutiselectListDemo">
  <apex:form >
  <apex:pageBlock >
      <apex:commandButton value="Check Selection" action="{!showSelected}"/>
      <apex:pageBlockSection >
          
          <apex:selectList value="{!selectedOptionsList}" size="4" multiselect="true">
                <apex:selectOptions value="{!multiSelectOptions}" />
          </apex:selectList>
      
      </apex:pageBlockSection>
  
      <apex:pageBlockSection >
      <apex:pageBlockSectionItem >
      <apex:outputLabel value="Selected Values"> </apex:outputLabel>
      <apex:inputText id="txtBox"/>
      </apex:pageBlockSectionItem>
      </apex:pageBlockSection>
      
  </apex:pageBlock>
  </apex:form>
  <script>
      document.getElementById('j_id0:j_id1:j_id2:j_id7:j_id8:txtBox').value = '{!selectedOptions}';
  </script>
</apex:page>
 
public class mutiselectListDemo 
{

    public PageReference showSelected() {
        return null;
    }

    private List<SelectOption> multiSelectOptionList =  new List<SelectOption>();
   
    public mutiselectListDemo()
    {
        multiSelectOptionList.add(new SelectOption('Option1' , 'Option1'));
        multiSelectOptionList.add(new SelectOption('Option2' , 'Option2'));
        multiSelectOptionList.add(new SelectOption('Option3' , 'Option3'));
        multiSelectOptionList.add(new SelectOption('Option4' , 'Option4'));
        multiSelectOptionList.add(new SelectOption('Option5' , 'Option5'));
    }

    public string selectedOptions {get;set;}
    public List<String> selectedOptionsList
    {   
        get; 
        set
            {
                selectedOptions = null;
                if(value != null && value.size() > 0)
                    {
                        Boolean addSeperater = false;
                        for(String le : value)
                            {
                                if(addSeperater)
                                    selectedOptions = selectedOptions + ',' + le;
                                else
                                    {
                                        selectedOptions = le;
                                        addSeperater = true;
                                    }
                            }
                    }
            }
    }
    public List<SelectOption> multiSelectOptions
        {   
            get
                {
                    return multiSelectOptionList;
                }
            set;
        }



}


 
Akhil AnilAkhil Anil
You can do it with a trigger as shown below. If you simply want to concatenate the values in the picklist, then remove the typecastings for the Integer and String from the below snippets.
 
trigger UpdateResult on Customer_Order__c (before insert, before update) {
  
  for(Trainingforce__Customer_Order__c ct:Trigger.New) {
  
     ct.Trainingforce__Result__c = String.ValueOf(Integer.ValueOf(ct.Trainingforce__Pick1__c) + Integer.ValueOf(ct.Trainingforce__Pick2__c));
     
  }
  
}

 
srinu vassrinu vas
Hi,
MIDHUN G REDDY

If you are developping visual force page then u can go by above code

or 

If you are working on standard pages

then 

1.create formula field which is of text type and place the below fomula 

2. text(pickfiled 1__c)+text(pickfield 2__c)

or 

you can go through by trigger

 
Selina Suarez 49Selina Suarez 49
Thank you this worked perfectly!
Selina Suarez 49Selina Suarez 49
@srinu vas