+ Start a Discussion
West415West415 

Get value of selet list on <apex: action="{!getValueOfSelectList}" />

Hi,

I have a custom visualforce page.  I have an <apex:selectList /> that has a default value set when the page loads.  How can I get the value of the selected item in the select list in my controller?
 
<apex:page controller="CustomController" showHeader="true" sidebar="true" action="{!showMeSelectedValue}">
In jQuery, the equivalent may be something like  $('#fieldID').val();   On page load, when the "showMeSelectedValue()" is called, I want to get the value of a given select list on my page.

How can this be done?
 
karthikeyan perumalkarthikeyan perumal
Hello, 

kindly read below thread for same kind of issue. you will get some idea for your's as well. 

https://developer.salesforce.com/forums/?id=906F000000096tTIAQ

hope this solve your issue. 


thanks
karthik

 
DeveloperSudDeveloperSud
Hi West,

I think this can be done in the constructor of the controller class. You just need to put the default value to the varible you want to use to show the 
dafault selected value in the vf page. Please refer the sample vf page .I think this will help you. Please let us know for anyother help.Thanks.
 
<apex:page controller="sample1yy" >
<apex:form >
<apex:pageBlock >
 <apex:selectList value="{!selectedValue}" size="1"  >
  <apex:selectOptions value="{!values}" />
  <apex:actionsupport action="{!actionMethod}" rerender="op1" event="onchange" />
 </apex:selectList>
 <apex:pageBlockSection id="op1">
  <apex:outputText value="Current Value Is Showing: {!selectedValue1}" />
 </apex:pageBlockSection>
</apex:pageBlock> 
</apex:form> 
</apex:page>
 
public with sharing class sample1yy {

    public List<SelectOption> values{get;set;}
    
    public string selectedValue{get;set;}
    public string selectedValue1{get;set;}
    
    public sample1yy(){  
    values= new List<selectoption>();
    // default value
    values.add(new selectoption('None','--NONE--'));
    List<String> valueToadd= new List<String>{'Value1','Value2','Value3'};
    for(String s: valueToAdd){
    values.add(new selectOption(s,s));
    }
    selectedValue1='None'; //default Value
    }
    
    public pagereference actionMethod(){
    selectedValue1=selectedValue;
    return null;
    }

    public pagereference onLoad(){
    selectedValue1=selectedValue;
    return null;
    }



}