+ Start a Discussion
Niraj Kumar 9Niraj Kumar 9 

Apex Select list is not working in salesforce1

Hi Guys,
Apex Select list is not working in salesforce1 while working fine in salesforce.
 <apex:selectList value="{!selectedUser}" size="1" id="UsrSelLst">
 
DeepthiDeepthi (Salesforce Developers) 
Hi Niraj,

apex:selectList
A list of options that allows users to select only one value or multiple values at a time, depending on the value of its multiselect attribute.

apex:selectOption
A possible value for an <apex:selectCheckboxes> or <apex:selectList> component. The <apex:selectOption> component must be a child of one of those components.

Check the below sample code:
<apex:page controller="ControllerClass">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection >
            <apex:outputLabel >State</apex:outputLabel>
            <apex:pageblockSectionItem >                
                <apex:selectList size="1" value="{!state}">
                    <apex:selectOptions value="{!states}"/>
                    <apex:actionSupport event="onchange" reRender="a"/>
                </apex:selectList>                
            </apex:pageblockSectionItem>
            <apex:outputLabel value="City"/>       
            <apex:pageblockSectionItem >
                <apex:selectList size="1" value="{!city}" id="a">
                    <apex:selectOptions value="{!cities}"/>
                </apex:selectList>
            </apex:pageblockSectionItem>      
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>
public class ControllerClass {

    public String state { get; set; }
    public String city { get; set; }
    
    public List<SelectOption> getStates() {
        List<SelectOption> stOptions = new List<SelectOption>();
        stOptions.add(new SelectOption('None','--None--'));
        stOptions.add(new SelectOption('AP','Andhra Pradesh'));
        stOptions.add(new SelectOption('TN','Tamil Nadu'));
        stOptions.add(new SelectOption('KA','Karnataka'));
        return stOptions;
    }

    public List<SelectOption> getCities() {
        List<SelectOption> ciOptions = new List<SelectOption>();
        if(state=='AP'){
            ciOptions.add(new SelectOption('VSKP','Vishakapatnam'));
            ciOptions.add(new SelectOption('BZA','Vijayawada'));
            ciOptions.add(new SelectOption('TPTY','Tirupati'));
        }
        else if(state=='TN'){
            ciOptions.add(new SelectOption('CHE','Chennai'));
            ciOptions.add(new SelectOption('CBE','Coimbatore'));
        }
        else if(state=='KA'){
            ciOptions.add(new SelectOption('SBC','Bangalore'));
            ciOptions.add(new SelectOption('MAQ','Mangalore'));
        }
        else if(state=='None'){
            ciOptions.add(new SelectOption('None','--None--'));
        }
        return ciOptions;
    }

}

Also, refer the below links:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectList.htm 

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectOption.htm

Hope this helps you!
Best Regards,
Deepthi