0

enter image description here

<apex:page controller="sampleCon">
<script type="text/javascript">
function submitform()
{
  document.myform.submit();
}
</script>
    
    <apex:form >
        <apex:selectList value="{!countries}"  size="1" onclick="submitform();">
            <apex:selectOptions value="{!items}"/>
        </apex:selectList><p/>
 
        <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
    </apex:form>
 
    <apex:outputPanel id="out">
         <p>You have selected: {!countries}</p>
        
    </apex:outputPanel>
</apex:page>

Class

public class sampleCon {
public string countries{get;set;}
    
        
    public PageReference test() {
        return null;
    }
        
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('US','US'));
        options.add(new SelectOption('CANADA','Canada'));
        options.add(new SelectOption('MEXICO','Mexico'));
        return options;
    }
        
   
}
1
  • P.S. If you meant this to be a Self-Answered Question, you can do this, but you should format the question and answer correctly.
    – sfdcfox
    Feb 11 at 22:34
2

You don't need to submit the form manually, just add an apex:actionSupport.

<apex:page controller="sampleCon">
    <apex:form id="form">
        <apex:selectList value="{!countries}"  size="1">
            <apex:selectOptions value="{!items}"/>
            <apex:actionSupport event="onchange" reRender="out" />
        </apex:selectList><p/>
    <apex:outputPanel id="out">
         <p>You have selected: {!countries}</p>
    </apex:outputPanel>
    </apex:form>
</apex:page>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.