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
sk kumarsk kumar 

my requirement is if i click check in a a certain checkbox in vf page then corresponding 4 cheboxes like a,b,c,d also checked automaticaly.can anyone provide me the code for this..!! thanx in advance..:)

Best Answer chosen by sk kumar
Valerijs ProkudinsValerijs Prokudins
sk kumar, please mark VPROK's answer as best if this fits you well.

All Answers

Ramu_SFDCRamu_SFDC
This is one of the solutions you can use(using javascript on visualforce page)

http://www.sfdcpoint.com/salesforce/select-all-checkbox-using-javascript-in-visualforce-page/
Valerijs ProkudinsValerijs Prokudins
no need in js here. use properties and rerender.
Add an action support to the "select all" checkbox and when it is checked - rerender whole checkboxes block. Of course you should set values in the controller before rerender.

sk kumarsk kumar
Hi Valerijs Prokudins  can u just provide me the code for this scenario. 
VPROKVPROK
here you are, this should be enough to understand a concept.
page:
<apex:page controller="devBoardExample">

<apex:form >
<apex:outputpanel id="checkall">
<apex:outputtext >CHECK ALL</apex:outputtext>
<apex:inputCheckBox value="{!selectAll}"/>
           <apex:actionSupport event="onclick" 
                                action="{!checkAll}" 
                                rerender="theTable"/>
</apex:outputpanel>

            
    <apex:dataTable value="{!wrappedList}" var="obj" id="theTable">
         <apex:facet name="caption">Account select all test page</apex:facet> 
        <apex:column >
            <apex:facet name="header">Name</apex:facet>
            <apex:outputLink value="//{!obj.Id}"> <apex:outputText value="{!obj.name}"/> </apex:outputLink>
        </apex:column>
        <apex:column >
            <apex:facet name="header">Selected</apex:facet>
            <apex:inputCheckbox disabled="false" value="{!obj.CheckBoxValue}"/>
        </apex:column>
    </apex:dataTable>




</apex:form>


</apex:page>
and the controller:
public with sharing class devBoardExample {
//props
public list<objWrapper> WrappedList{get;set;}
public boolean selectAll{get;set;}

//ivars

// constructor
public devBoardExample(){
	selectAll=false;
	list<Account> acclist = [SELECT Id, Name FROM Account LIMIT 4];
	WrappedList = new list<objWrapper>();
	for(Account acc:acclist){
		WrappedList.add(new objWrapper(acc)); 
	}
} 
// methods
// this method checks/unchecks checkboxes on all objects
public pageReference checkAll(){
	if(selectAll == true){
		selectAll = false;
		for (objWrapper obj: WrappedList){
			obj.setCheckBoxValue(true);
		}
	}else{
		selectAll=true;
		for (objWrapper obj: WrappedList){
			obj.setCheckBoxValue(false);
		}
	}
	return null;
}

//helper class to handle object + checkbox
public class objWrapper{
private Account acc;
public boolean checkBoxValue;

public objWrapper (Account acc){
	this.acc = acc;
	this.checkBoxValue = false;
}

public String getId(){
	return acc.Id;
}

public String getName(){
	return acc.Name;
}

public boolean getCheckBoxValue(){
	return checkBoxValue;
}
public pageReference setCheckBoxValue(boolean value){
	checkBoxValue = value;
return null;
}
}
}
hope this will help


Valerijs ProkudinsValerijs Prokudins
sk kumar, please mark VPROK's answer as best if this fits you well.
This was selected as the best answer
VPROKVPROK
I mean VROKS answer with a code =) Valerijs Prokudins is just my another acc in one of the projects, and I post under this account accidentally :)
Thanks