The way I am currently getting the inputfield picklist values into my custom controller is by using a javascript to find the selected value like this:

function CallPick1(id) {
        var type = document.getElementById(id).value;

the pick1(type); calls an apex:actionFunction with name "pick1" which passes the value of the picklist to a custom controller like so:

<apex:actionFunction name="pick1" action="{!passField}" rerender="theform">
<apex:param name="getPick1" value=""/>

And it pulls the value of the picklist from the vf page into an apex controller with the function !passField like this:

public void passField() {
        String pickvalue1 =System.currentPageReference().getParameters().get('getPick1');
        system.debug('Picklist 1 Value: '+pickvalue1);

I have the same functions, etc for pick2. Although I need it so that if pick1's value changes to A then pick2's value should change to B and it needs to display the value of pick2 on the vf page inside the picklist selector. I still need pick2 to show other values inside the picklist and still be able to change pick2's values however.

1 Answer 1

    <apex:page controller="TestClassTwo">
        <apex:selectList value="{!countries}" size="1" onchange="someapexcall()">
            <apex:selectOptions value="{!items}"/>
        <apex:selectList value="{!capitalval}" size="1" id="out2">
            <apex:selectOptions value="{!Items2}"/>
        <apex:actionFunction name="someapexcall" action="{!updatePick}" rerender="out2"/>

    public class TestClassTwo {
    public String countries{get;set;}
    public String capitalval{get;set;}
    Map<String,String> somemap=new Map<String,String>();
    public List<SelectOption> Items{get;set;}
    public List<SelectOption> Items2{get;set;}
        public TestClassTwo(){
            Items2 = new List<SelectOption>();
            Items2.add(new SelectOption('DC','DC'));
            Items2.add(new SelectOption('Quebec','Quebec'));
            Items2.add(new SelectOption('Colombo','Colombo'));
            somemap.put('Sri Lanka','Colombo');
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('US','US'));
            options.add(new SelectOption('CANADA','Canada'));
            options.add(new SelectOption('Sri Lanka','Sri Lanka'));
        public void updatePick(){

This Kinda does what's wanted up there.

  • Not exactly what I'm looking for. I need it to update the chosen value on an <apex:InputField> with preexisting values, not adding new ones. Dec 26, 2019 at 14:14
  • Can you add your picklists or add some more code?
    – user61140
    Dec 26, 2019 at 14:19
  • My picklists are defined as: <apex:inputField id="pick1" value="{!Product2.List_1__c}" onchange="CallPick1('{!$Component.pick1}');"/> Dec 26, 2019 at 18:52

You must log in to answer this question.

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