How to check atleast one checkbox is checked?

Total Post:341


 1611  View(s)
Rate this:

I want to check at least one checkbox should be checked before unload the page or clicking on btn save.

<asp:GridView ID="grdTest" runat="server" DataKeyNames="Id" AutoGenerateColumns="False" HorizontalAlign="Center" GridLines="None" onrowcreated="grdTest_RowCreated">

  <asp:TemplateField >


        <asp:TextBox ID="txtText" Rows="10" Columns="40" runat="server" TextMode="MultiLine"   Height="55px" Text='<%# Eval("Text") %>'></asp:TextBox>

        <asp:Button ID="btnSave" runat="server" Text="Save" CommandName="Save"/>           

        <span id="checkbox">

        <asp:RadioButton ID="rbtnTest"  runat="server" Checked='<%# Eval("Correct") %>' TextAlign="Left"  Height="28px" />




        <asp:TextBox ID="txtText" Rows="10" Columns="40" runat="server" TextMode="MultiLine" />

        <asp:Button ID="btnSave" runat="server" Text="Save" CommandName="Save"/>

        <asp:CheckBox ID="rbtnTest" runat="server"  Enabled="true" TextAlign="Left"/>




plz some one help me?

  1. Re: How to check atleast one checkbox is checked?

    Hi Ankit, 

    try this:

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

    function Validate_Checkbox()


        var chks=document.getElementsByTagName('input');  

        var hasChecked = false;

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


                if (chks[i].checked)


                        hasChecked = true;




          if (hasChecked == false)


                    alert("Please select at least one checkbox..!");

                    return false;


                return true;



    and on Submit Button you have to write

    OnClientClick="return Validate_Checkbox()"


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.