You need to sign in to do that
Don't have an account?
lavanya gottumukkala
Restricting picklist values through apex and visualforce
Hi All,
I have the below requirement.
On registration page we have two picklist fields 'country' and 'Taxes'.By default when page is loaded first time,I want to set country as 'India' and Taxes as 'PAN'.But once user changed the country from India to any other,then I would like to display the Taxes related to that country only(through select list).How it can be achieved through actionfunction?
Thanks in advance.
I have the below requirement.
On registration page we have two picklist fields 'country' and 'Taxes'.By default when page is loaded first time,I want to set country as 'India' and Taxes as 'PAN'.But once user changed the country from India to any other,then I would like to display the Taxes related to that country only(through select list).How it can be achieved through actionfunction?
Thanks in advance.
Please try this below sample code.
VisualForce Page:
Controller:
Replace cities with taxes and city names with tax names.
Hope it helps you.
Regards,
Jyothsna D.
Write a method which returns select option list based when pass the country. Then rerender the tax list based on the parsed country. The code is more like a guidance and let me know if you have any problem.
In the controller do something like this
public String selectedCountry{get;set;}
public String selectedTax {get;set;}
private list<SelectOption> countryTax(String countryName){
// implement the logic that returns the list of selectOptions based on country
}
public list<SelectOption> getTaxes(){
if(selectedCountry != null){
return this.countryTax(selectedCountry);
}else{
// give error message
}
return null;
}
public list<SelectOption> getCountries{
// return the country option list
}
In page you can do
<apex:selectList id="fld1" value="{!selectedCountry}" multiselect="false" size="1" >
<apex:selectOptions value="{!Countries}"/>
<apex:actionSupport event="onselect" action="{!Taxes} rerender="taxPanel
" status="SearchStatus immediate="true"/>
</apex:selectList>
<apex:outputpanel id="taxPanel">
<apex:selectList id="fld1" value="{!selectedTax }" multiselect="false" size="1" >
<apex:selectOptions value="{!Taxes}"/>
</apex:selectList>
</apex:outputpanel>