How To Select One Check Box From A Group Of Checkboxes

Posted by in JavaScript category on for Intermediate level | Points: 250 | Views : 27949 red flag
Rating: 5 out of 5  
 1 vote(s)

We can access the check box in grid control in client side using java script


In This article we shall learn how to restrict user to select multiple recipients.

Using the code

We can access the check box in grid control in client side using java script.

When there are two recipients groups available to user to send messages to them .for Group 1 user will be allow to send one recipient at a time , for Group 2  he will  be allow to send multiple. For 2nd case there is no need to write any JavaScript code because check boxes allow us select multiple at a time.


For Group 1 we need to write below java script code:

<script type="text/javascript" language="javascript">

function checkboxClicked(event , idfrag)  


            var currentCheckBox = event.srcElement ||;        

            var inputs = document.getElementsByTagName("input");  

            for (var i = 0; i < inputs.length; i++)  


                var input = inputs[i];            

                if ( ==  


                if ( < 0)  


                //clear out the rest of the checkboxes  

                if (input.type && input.type == "checkbox")  


                    input.checked = false;  






.ASPX file::

<asp:GridView ID="grdRecipients" runat="server"   DataKeyNames="id"

                  AutoGenerateColumns="False" CellPadding="7" GridLines="None"  Width="100%" EmptyDataText="No Recipients Available" HeaderStyle-BackColor="White"  BackColor="#FBF9FC"  AlternatingRowStyle-BackColor="#F0EAF6"  >

<RowStyle />


    <asp:TemplateField HeaderText="">


          <asp:CheckBox ID="chkAssign" runat="server"  ToolTip='<%# Eval("id") %>' AutoPostBack="true"onclick="checkboxClicked(event,'chkAssign')"  />


       <ItemStyle Width="25%" />



 <FooterStyle CssClass="display" />

      <HeaderStyle BackColor="White" CssClass="display" />



Single Check box selection from a group of check boxes is a very rare condition. If any other solution easier then this please respond to this article.

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: ravi kasarla
Member Level: Starter
Member Status: Member
Member Since: 6/30/2011 7:08:03 AM
Country: India
Ravi Kasarla
HI , i am currently working for oztek software pvt ltd as a web developer.i am having 1.5 years experience on .net frame work and php.

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)