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
akshay desai 9akshay desai 9 

how to compare custom picklist value in vf controller


I used this code in my vf controller

 public List<SelectOption> getmonth() {
          List<SelectOption> options = new List<SelectOption>();
          options.add(new SelectOption('JANUARY','January'));
          options.add(new SelectOption('FEBRUARY','February'));
          options.add(new SelectOption('MARCH','March'));
        options.add(new SelectOption('APRIL','April'));
        options.add(new SelectOption('MAY','May'));
        options.add(new SelectOption('JUNE','June'));
        options.add(new SelectOption('JULY','July'));
        options.add(new SelectOption('AUGUST','August'));
        options.add(new SelectOption('SEPTEMBER','September'));
        options.add(new SelectOption('OCTOBER','October'));
        options.add(new SelectOption('NOVEMBER','November'));
        options.add(new SelectOption('DECEMBER','December'));                           
          return options;
      }

now I want to show data of may if user select may  how should I do that?
Khan AnasKhan Anas (Salesforce Developers) 
Hi Akshay,

Greetings to you!

Below is the sample code. Kindly modify the code as per your requirement.

Visualforce:
<apex:page controller="PicklistValuesC">
    <apex:form > 
        <apex:commandbutton value="Show Values" action="{!show}"/>
        
        <apex:pageBlock >    
            <apex:outputLabel > Countries : </apex:outputLabel>
            <apex:selectList size="1" value="{!selectedCountry}">
                <apex:selectOptions value="{!countrieLst }"/>
            </apex:selectList> <br/>
            
            <apex:outputLabel > Gender : </apex:outputLabel>
            <apex:selectRadio value="{!selectedGender}"> 
                <apex:selectOptions value="{!genderLst}"/>
            </apex:selectRadio>  
            
            <apex:outputLabel > Hobbies :</apex:outputLabel>
            <apex:selectList size="1" value="{!selectedHobby}">
                <apex:selectOption itemLabel="--None--" itemvalue=""></apex:selectOption>
                <apex:selectOption itemLabel="Swimming" itemvalue="Swimming"></apex:selectOption>
                <apex:selectOption itemLabel="Reading" itemvalue="Reading"></apex:selectOption>
                <apex:selectOption itemLabel="Cricket" itemvalue="Cricket"></apex:selectOption>
            </apex:selectList>     
        </apex:pageBlock> 
        
        <apex:pageBlock title="selected values">
            <apex:outputText value="{!selectedValues}" style="color:red"/>   
        </apex:pageBlock>
    </apex:form>
    
</apex:page>

Controller:
public class PicklistValuesC {
    
    public List<SelectOption> countrieLst {get;set;}
    public List<SelectOption> hobbiesLst {get;set;}
    public List<SelectOption> genderLst {get;set;}
    
    public String selectedCountry{get;set;}
    public String selectedHobby {get;set;}
    public String selectedGender {get;set;}
    public String selectedValues {get;set;}
    
    
    public PicklistValuesC(){
        countrieLst = new List<SelectOption>();
        hobbiesLst = new List<SelectOption>();
        genderLst = new List<SelectOption>();
        
        countrieLst.add(new SelectOption('','--None--'));
        countrieLst.add(new SelectOption('India','India'));
        countrieLst.add(new SelectOption('China','China'));
        countrieLst.add(new SelectOption('US','US'));
        
        
        genderLst.add(new SelectOption('Male','Male'));
        genderLst.add(new SelectOption('Female','Female'));
        
    }
    
    public pageReference show(){
        selectedValues = 'Selected country: '+selectedCountry +' --> Selected Hobbies: '+selectedHobby+' --> Gender: '+selectedGender;
        return null;
        
    }
}

Reference: http://sfdcsrini.blogspot.com/2014/07/how-to-use-apexselectoptions-and.html

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
akshay desai 9akshay desai 9
Hi Anas I want to show the data of user selected month on pdf 
for that i need if else if user select may show data 
for that how can i fetch the value of a picklist