0

Is it possible to have dependent pick list based on radio button.? suppose i have one picklist x,y,z,1,2,3 and two radio button letters and numbers when i select letters picklist values will be x,y,z and when i select numbers then picklist values will be 1,2,3.

please help me out for this requirement.

2 Answers 2

3

VF page Code:

<apex:form >

<apex:actionfunction name="refreshvalue" action="{!classMethod}" rerender="pklist"/>

    <apex:selectRadio value="{!Val}" onchange="refreshvalue()">
            <apex:selectOptions value="{!radioValues}"/>
    </apex:selectRadio>

    <apex:selectList size="1" id="pklist">
             <apex:selectOptions value="{!PicklistValues}"/>
    </apex:selectList>

</apex:form>

Controller Class

public class DepPclass {

    public  List<SelectOption>  PicklistValues { get; set; }
    public  List<SelectOption>  radioValues { get; set; }
    public String Val { get; set; }

    public depPclass(){

        PicklistValues = new List<SelectOption>();
        radioValues = new List<SelectOption>();

        radioValues.add(new SelectOption('Letters','Letters')); 
        radioValues.add(new SelectOption('Number','Number')); 

    }
    public PageReference classMethod() {

        if(val == 'Letters'){

            PicklistValues.clear();
            PicklistValues.add(new SelectOption('a','A')); 
            PicklistValues.add(new SelectOption('b','B')); 
            PicklistValues.add(new SelectOption('c','C'));

        }else{

            PicklistValues.clear();
            PicklistValues.add(new SelectOption('1','1')); 
            PicklistValues.add(new SelectOption('2','2')); 
            PicklistValues.add(new SelectOption('3','3')); 

        }
        return null;
    }

}
2
  • it is working fine. But how to save select option list values into text field of an object. i am giving the value attribute as text field name but it is giving error Formula expression is required for attribute value in <apex:selectList>
    – Cloud Arch
    Jun 19, 2015 at 13:57
  • 1
    Use this <apex:selectList size="1" value="{!selVal}" id="pklist"> code and define selval in class as public string selval { get; set; } Jun 20, 2015 at 10:44
0

You can create Vf page for that, create a apex:selectlist, and set selectoptions=collection and set collection value on the basis of which radio button is on, you can also use rerendering.

1
  • Hi amit can you elaborate using some sample code
    – Cloud Arch
    Jun 19, 2015 at 10:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .