I think I am missing something basic. I have two select lists: Region and District. Based on region selection, the district values should get updated.
Following is the code for VF:
<apex:page Controller="UserStatsController">
<apex:sectionHeader title="Goal Revision Dashboard" subtitle="District View"/>
<apex:pageBlock title="User Stats">
<apex:form >
<apex:outputLabel value="Region" />
<apex:selectList value="{!regn}" size="1" id="Region" required="true">
<apex:selectOptions value="{!Valuesr}" />
<apex:actionSupport event="onchange" reRender="districtSelect"/>
</apex:SelectList>
<apex:outputPanel id="districtSelect">
<apex:outputLabel value="District"/>
<apex:selectList value="{!dist}" size="1" id="dist" required="true">
<apex:selectOptions value="{!Values}"/>
</apex:selectList>
</apex:outputPanel>
</apex:page>
And following is the controller
public with sharing class UserStatsController {
public string regn {get; set;}
public string dist {get; set;}
public list <SelectOption> getValuesr()
{
list <selectoption> lsreg = new List<selectoption> ();
lsreg.add(new SelectOption('', '--None--'));
for (User_Stats__C Rgn : [SELECT Region__c FROM User_Stats__C where Region__c != null and Region__c != 0 and District__c != null and District__c != '0' limit 10])
{
lsreg.add(new selectoption(string.valueOf(Rgn.Region__c), string.valueOf(Rgn.Region__c)));
}
return lsreg;
}
public list <SelectOption> getValues()
{
list <selectoption> ls = new List<selectoption> ();
ls.add(new SelectOption('', '--None--'));
Integer regnInt = (regn!=null) ? Integer.valueOf(regn) : -1;
for (User_Stats__C dist : [SELECT District__c FROM User_Stats__C where Region__c =: regnInt and District__c != '' and Region__c != null and Region__c != 0 limit 10])
{
ls.add(new selectoption(dist.District__c, dist.District__c));
}
return ls;
}
}
Thanks.