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
Arvind010Arvind010 

How to check all the checkboxes in a page by clicking on a checkbox using javascript?

In a visual force page, when i click one checkbox, i need to check all the other checkboxes in a page which are created by using select options.


Code:
<apex:inputCheckBox id="chkbox" onclick="var checkboxvalue=document.getElementById('{!$Component.Acctlist}').value;if(this.checked) checkboxvalue=true;"/>
<b><apex:outputlabel value="Check All the Accounts" style="font-weight:normal"></apex:outputlabel></b><br/><br/>        
    <apex:selectCheckboxes value="{!AccountsList}" id="Acctlist" layout="pageDirection">
                 <apex:selectOptions value="{!AccountList}"></apex:selectOptions>
    </apex:selectCheckboxes><br/> 

This is the code which i tried. I assigned true value to the selectCheckboxes id.But it was working.

Please provide me the solution.

TLFTLF
You might want to try this:
 
Code:
<apex:inputCheckBox id="chkbox" onclick="var checkbox=document.getElementById('{!$Component.Acctlist}');if(this.checked) checkbox.value=true;"/>
<b><apex:outputlabel value="Check All the Accounts" style="font-weight:normal"></apex:outputlabel></b><br/><br/>        
    <apex:selectCheckboxes value="{!AccountsList}" id="Acctlist" layout="pageDirection">
                 <apex:selectOptions value="{!AccountList}"></apex:selectOptions>
    </apex:selectCheckboxes><br/> 

 
Tushar MahadikTushar Mahadik
This is not working....please suggest another solution...here is my code....  
                                                                                                                           
<apex:inputCheckBox id="chkbox" onclick="var checkbox=document.getElementById('{!$Component.select_state}');if(this.checked) checkbox.value=true;"/>       <font face="calibri" size="3"><b>Select State :</b></font>
   <apex:selectCheckboxes value="{!states}" style="width:150px;align:Left;background-color: #fff;border-style: solid;border-color:#D2691E;border-width:2px" id="select_state" layout="pageDirection">                   
        <apex:SelectOptions value="{!AttStates}" />
        <apex:actionsupport event="onchange" rerender="select_dist,child_blocks"/>    
  </apex:selectCheckboxes>