+ Start a Discussion
Bijay SahuBijay Sahu 

onClick is not firing for apex:inputCheckbox to call apex class method

Hi All,
I have a dynamic table and reach row binding with inputCheckbox. onClick i am calling an Apex class methos but method is not calling. Could anyone please help and Thanking you in advance.

My Apex Page
<apex:page controller="DynamicCheckBox_Ctrl">
  <apex:form >
      <apex:pageBlock >
          <apex:pageBlockSection columns="1">
              <apex:inputText value="{!firstValue}" label="Enter Field Name"/>
              <apex:inputText value="{!secondValue}" label="Enter another Filed Name"/>
          <apex:pageBlockButtons location="top">
              <apex:commandButton value="Get Data" action="{!showValues}"/>
              <apex:commandButton value="Delete" onclick="if (!confirmDelete()) return false;" action="{!deleteAccount}"  />
          <apex:outputPanel rendered="{!hideTable}">
              <apex:pageblockTable value="{!accList}" var="acct" >
                  <apex:column >
                    <apex:inputCheckbox onclick="storeAccoutIds({acct.id},selected)" />
                  <apex:repeat value="{!lstFields}" var="filedName">
                      <apex:column value="{!acct[filedName]}"/>
      function confirmDelete()
        return confirm(‘Are you sure you want to delete?’);

Apex Class

public class DynamicCheckBox_Ctrl {
    public string prepareQuery{get;set;}
    public string firstValue{get;set;}
    public string secondValue{get;set;}
    public boolean hideTable{get;set;}
    public boolean enableDelButton{get;set;}
    public list<Account> accList{get;set;}
    public List<String> lstFields{get;set;}
    //store account id, if checkbox is checkedselectedcheckbox
    public Map<String,Boolean> mapAccountId = new Map<String,Boolean>();

    public void storeAccoutIds(string accId, boolean isSelected)
            enableDelButton = true;
    //Get records from datanase and send to apex page
    public void showValues()

            //Add all the fileds into a list
            lstFields=new list<String>();


            //Prepare dynamic query
            prepareQuery = 'SELECT id,'+firstValue+','+secondValue+' FROM Account';

            //Execute query
            accList = new List<Account>();
            accList = Database.query(prepareQuery);

        }catch(Exception ex){
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.Error, ex.getMessage());
I want to give you a preliminary thought..
onclick attribute on apex:inputcheckbox may not be a valid
if you want to use this, first use a JavaScript method and use actionFunction , this might work. 
otherwise, I will do some research on documentation and get back to you.