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
siva kumar 176siva kumar 176 

How to get field values from vf page to apex class controller

I have a checkbox in my vf page which is using custom controller. I need to get check box value true in apex class controller when it is checked, so that I can perform my logic based on that checkbox value. How to do that?
Sure@DreamSure@Dream
you can call a controller method onchange of the checkbox field.
<apex:inputcheckbox value="{!field}> 
     <apex:actionSupport event="onchange" action="{!methodname}"       rerender="panelId"/> 
</apex:inputcheckbox>

Mark this as solution, if it helped you.

Thanks
Karthi XaviKarthi Xavi
Hello Siva try with following code,
<!---------Page---------->
<apex:inputCheckbox value="{!CheckBoxValue}" id="checkBox">
      <apex:actionSupport event="onclick" action="{!getSelected}"/>
<apex:inputCheckbox/>

<!---------Controller---------->
public class CheckBoxController {
public String CheckBoxValue{get;set;}

   public PageReference getSelected(){
      if(CheckBoxValue==true) {
         //do your fuctionality
      } else{
      }
   return Null
   }
}
Nitish TalekarNitish Talekar
Hi Siva,

Check below sample code:

Visualforce Page =>

<apex:page controller="passparamFromVFtoController">
    <!-- Pass parameters from visualforce page to controller -->
    <apex:form >
            <apex:pageblock >
                  Input your query <apex:inputText value="{!myInputQueryString}"/>
                 <apex:commandButton value="Submit" reRender="DisplayInputQueryID" action="{!myInputQuery}"/>
            </apex:pageblock>
            <apex:pageblock >
                 <b>Output : </b><apex:outputText value="{!myoutputString}" id="DisplayInputQueryID"/>
            </apex:pageblock>
    </apex:form>
</apex:page>


Apex Controller =>

Public with sharing class passparamFromVFtoController {
  Public string myInputQueryString{get;set;}
  Public string myoutputString{get;set;}
   
  Public void myInputQuery(){
  myoutputString = myInputQueryString ;
  }
}

Please mark this as bext answer if it works for you.

Thanks,
Nitish