+ 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

This is one of the solutions you can use(using javascript on 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. 
here you are, this should be enough to understand a concept.
<apex:page controller="devBoardExample">

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

    <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:facet name="header">Selected</apex:facet>
            <apex:inputCheckbox disabled="false" value="{!obj.CheckBoxValue}"/>


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


// constructor
public devBoardExample(){
	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){
		for (objWrapper obj: WrappedList){
	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
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 :)