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
Adil_SFDCAdil_SFDC 

Select All check box

Check box to Select All on VF Page. I am trying this but no go

 

<apex:page standardController="Listing__c"   extensions="TFNController" id="myPage" showHeader="false">
  
 
       <apex:pageMessages id="messages"/> 
 <apex:form id="myform" >

<apex:PageBlock title="TFN Provisioning for Listing :" />
<apex:PageBlock id="pageload">
  <apex:PageBlockSection columns="1" id="theSection" > 
<apex:outputPanel style="vertical-align:top" >
  <table border="1" class="list" width="100%" cellpadding="0" cellspacing="0" id="aheadertable" >
                 <tr >  
                
                  <td width="2%"  style="font-weight:bold;text-align:center;vertical-align:bottom" rowspan='2'><b>
                    <apex:inputCheckbox id="SelectAll"   onclick="selectAll()" /></b></td>
</tr>
  </table>  
            </apex:outputPanel> 
           <apex:outputPanel style="vertical-align:top" id="test">
      <apex:repeat var="TFNAffiliate" value="{!TFNVFResults}" id="TFNAffiliateId"> 
                     <table border="0" width="100%" class="list" cellpadding="0" cellspacing="0" id="atable" >
                        <tr class="row" style="persist: location;">
                            <td width="2%" style="text-align:center" >
                             <apex:inputCheckbox id="select" value="{!TFNAffiliate.selected}" styleclass="select" /> 
                           </td>
 </table> 
                   </apex:repeat>   
                   </apex:outputPanel>    
                  </apex:PageBlockSection> 
                      </apex:PageBlock>
                           </apex:form>
<script>
function selectAll()
 {
   // var listSize = {!TFNVFResults.size};
   // alert(!TFNVFResults.size);
   // var i;
     var select;
  var selectall =  document.getElementById('{!$Component.myPage.myform.pageload.theSection.selectAll}');


  //if (selectall.checked){
  alert(selectall.value);
   
 // }
for (i = 0; i < listSize; i++) {
          
      select = document.getElementById('myPage:myform:pageload:theSection:TFNAffiliateId:'+i+':select}');
      }
 alert('test'+select.value);
 }
 </script>
   
</apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
jayjaysjayjays

Hi,

 

I would use an action support and controller logic to select/deselect all.

 

<apex:inputCheckbox id="SelectAll" onclick="selectAll()" value="{!allSelected}">
	<apex:actionSupport action="{!selectAll}" rerender="test" event="onchange"/>
</apex:inputCheckbox>

 and the controller:

 

public boolean allSelected{get;set;}
public PageReference selectAll(){
	for (TFNAffiliate__c TFNAffiliate:TFNVFResults){
		TFNAffiliate.selected=allSelected;}
	return null;
}

 Not sure what sObject TFNVFResults is a list of, so replace TFNAffiliate__c with the api name of the object.

 

Thanks,

James.

All Answers

Adil_SFDCAdil_SFDC

changed my Java script to 

 

<script type="text/javascript">
$('document').ready(function(){
$('#selectAll').click(function(){
if($(this).is(':checked')){
$('.select').attr("checked",true);
}
else{
$('.select').attr("checked",false);
}
})
});
</script>

 

still no go

jayjaysjayjays

Hi,

 

I would use an action support and controller logic to select/deselect all.

 

<apex:inputCheckbox id="SelectAll" onclick="selectAll()" value="{!allSelected}">
	<apex:actionSupport action="{!selectAll}" rerender="test" event="onchange"/>
</apex:inputCheckbox>

 and the controller:

 

public boolean allSelected{get;set;}
public PageReference selectAll(){
	for (TFNAffiliate__c TFNAffiliate:TFNVFResults){
		TFNAffiliate.selected=allSelected;}
	return null;
}

 Not sure what sObject TFNVFResults is a list of, so replace TFNAffiliate__c with the api name of the object.

 

Thanks,

James.

This was selected as the best answer
Adil_SFDCAdil_SFDC

Amazing Thanks ..It worked