How can I retrieve the checkboxes that are selected (ticked or equal to true) on my VF page if these checkboxes were created dynamically?
The checkboxes are being displayed on my VF Page like this:
<apex:selectCheckboxes value="{!choices}" onchange="CalcCheckBox(this)">
<apex:selectOptions value="{!listEvents}"/><br/>
</apex:selectCheckboxes>
And these are my 2 methods used to generate the checkboxes:
//String array to keep track of the ids of choices
public String[] choices { get; set; }
//listEvents of select options to populate select boxes
public list<SelectOption> getlistEvents() {
list<SelectOption> options = new list<SelectOption>();
for (Presentation__c ow : [Select Id, Display_Name__c FROM Presentation__c WHERE (Status__c='Open' AND Date_of_Presentation__c >= TODAY) ORDER BY Date_of_Presentation__c ASC LIMIT 100]) {
options.add(new SelectOption(ow.Id, ow.miiEventV1__Display_Name__c));
}
return options;
}
Best Answer
The choices string array will contain just the selected values, as if it were a multi select pick list not using a field. If the array is empty, no values were selected.
Edit
Here's a working demo:
Controller
Page