+ Start a Discussion
SalesforceLearnerNewbieSalesforceLearnerNewbie 

Pass the checked box of slds back to controller

I have this vf page code:

 <div class="slds-checkbox">
                                                    <input type="checkbox" name="default" id="checkbox-27" onchange="{!subj}" value="thanksgiving" />
                                                    <label class="slds-checkbox__label" for="checkbox-27">
                                                      <span class="slds-checkbox_faux"></span>
                                                      <span class="slds-form-element__label"><apex:commandLink action="{!showPopup}" value="Thanksgiving"></apex:commandLink></span>
                                                    </label>
                                                  </div>


When I check the box for "thanksgiving" then it should save this "thanksgiving" value back to my controller. Please do note that, I might not have only 1 checkbox but many checkboxes so is there a way to loop the list<String> subject. then each element in the string will be represented next to checkbox, then when user check any of the checkbox, Example, when user checked "thanksgiving", "No way" and "One way" then these checked information will be passed back to controller. 

Is there a way to do so?
Parmanand PathakParmanand Pathak
Hello,

Use apex:input instead of using only input.
<apex:inputCheckbox id="Save" value="{!Save}">
Public String Save{get; set;}
Thanks,
Parmanand Pathak
 
SalesforceLearnerNewbieSalesforceLearnerNewbie

Hi, 

 

But the problem is if I used apex:inputcheckbox then the return value back to controller will be either true or false. However, what I wanted to return back to the controller is not just "true" or "false" but the value selected based on the checked box. Example, user checked a box for value "I have something". then this checked box value will be returned back to the controller 

Parmanand PathakParmanand Pathak
Hi,
You can take string variable inside the apex class and set the value of the variable according to the checkbox value selected (true/false).
Public String Save{get; set;}
String thanksgiving_variable = ''; //Use this variable

if(Save == 'true')
{
	thanksgiving_variable  = 'thanksgiving';   //setting the value
}
Mark this answer as resolved if you got the solution so that it will come under resolved category.

Thanks,
Parmanand Pathak
 
SalesforceLearnerNewbieSalesforceLearnerNewbie

Hi sir, 

 

What about if the value is not just fix to "thanksgiving" only. But what about it keeps changing the value. There is no way that I am going to rename one by one everytime right? Is there a more better way to do it?