I select the country in the frist field than should show the second field the state, that works fine. But If I select the state I want to select the city in the third field. It doesn't work.
<apex:page controller="ctlDepPickLst">
<apex:form >
<apex:pageBlock>
<apex:pageBlockSection columns="2">
<apex:pageblockSectionItem>
<apex:outputLabel value="Country"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem>
<apex:selectList size="1" value="{!country}">
<apex:selectOptions value="{!countries}"/>
<apex:actionSupport event="onchange" reRender="a"/>
</apex:selectList>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem>
<apex:outputLabel value="State"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem>
<apex:selectList size="1" value="{!state}" id="a">
<apex:selectOptions value="{!states}"/>
<apex:actionsupport event="onchange" reRender="b"/>
</apex:selectList>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem>
<apex:outputLabel value="City"/>
</apex:pageblockSectionItem>
<apex:pageblockSectionItem>
<apex:selectList size="1" value="{!city}" id="b">
<apex:selectOptions value="{!city}"/>
</apex:selectList>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller Class :
public class ctlDepPickLst {
public String country {get;set;}
public String state {get;set;}
public String city {get;set;}
public List<SelectOption> getCountries()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('None','--- Select ---'));
options.add(new SelectOption('US','United States'));
options.add(new SelectOption('IN','India'));
return options;
}
public List<SelectOption> getStates()
{
List<SelectOption> options = new List<SelectOption>();
if(country == 'US')
{
options.add(new SelectOption('CO','Colorado'));
options.add(new SelectOption('NE','Nevada'));
options.add(new SelectOption('TE','Texas'));
}
else if(country == 'IN')
{
options.add(new SelectOption('BI','Bihar'));
options.add(new SelectOption('KE','Kerala'));
options.add(new SelectOption('MA','Manipur'));
}
else
{
options.add(new SelectOption('None','--- Select ---'));
}
return options;
}
public List<SelectOption> getCity()
{
List<SelectOption> options2 = new List<SelectOption>();
if(state == 'CO')
{
options2.add(new SelectOption('BE','CO1'));
options2.add(new SelectOption('MU','CO2'));
}
else
{
options2.add(new SelectOption('MI','test1'));
options2.add(new SelectOption('AB','test2'));
}
return options2;
}
}