function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rohitash yadavrohitash yadav 

submit visualforce page when click on apex:selectCheckboxes

Hi All,

I have created multiple checkbox from selectoption. Now I want to submit the form and filter record based on selected checkbox.

Visualforce code:
 
<apex:selectCheckboxes value="{!checkboxSelections}" >
  <apex:selectOptions value="{!MyCheckboxes}"  >
     <apex:actionSupport event="onclick" action="{!getSelectedOrder}" /> 
  </apex:selectOptions>
</apex:selectCheckboxes>
APex code:
 
public PageReference getSelectedOrder() {
     system.debug('yadav');
     return null;
}

public list<string> checkboxSelections {get;set;}  //holds the values of the selected checkboxes

public list<selectOption> getMyCheckboxes(){
    system.debug('rohiatsh');
    //create list of checkboxes
    list<selectOption> myOptions = new list<selectOption>();
    for(integer i=0;i<5;i++){
    myOptions.add(new selectOption(string.valueof(i),string.valueof(i)));
     } 
    return myOptions;
 }


When I click on any chekbox then getSelectedOrder is not getting called. Can anyone help me.
Shubham Prajapati 19Shubham Prajapati 19
<apex:actionFunction name="getSelectedOrder" action="{!getSelectedOrder}" rerender="msg"/>        
        <apex:selectCheckboxes value="{!checkboxSelections}" onchange="getSelectedOrder();">
            <apex:selectOptions value="{!MyCheckboxes}"/>
        </apex:selectCheckboxes>
Use actionFunction instead of actionSupport and it'll work like charm. Mark as best answer if it solves your problem. Thank you.
Shweta GargShweta Garg
Hi rohitash,

Action support should be added to selectcheckboxes component instead of selectoptions.
 
<apex:selectCheckboxes value="{!checkboxSelections}" >
	 <apex:actionSupport event="onclick" action="{!getSelectedOrder}" /> 
  <apex:selectOptions value="{!MyCheckboxes}"  />
 
</apex:selectCheckboxes>
Please  give it a try to this code. I will work fine.Please mark it as solved if it helps you.
Thanks,