Validate Checkboxlist using Jquery in asp.net | ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

Validate Checkboxlist using Jquery in asp.net

Introduction: In this article I have explain how we can validate the CheckBoxlist using Jquery in asp.net.
Validate Checkboxlist

Description:
Add a webform to project. Drag and drop the CheckBoxlist and button controls from Toolbox. Desgin the .aspx as shown below:
<table align="center"><tr><td>Known Language:</td><td>
        <asp:CheckBoxList ID="chklanguage" runat="server"
            RepeatDirection="Horizontal">
        <asp:ListItem Text="English" Value="0"></asp:ListItem>
        <asp:ListItem Text="Hindi" Value="1"></asp:ListItem>
        <asp:ListItem>Punjabi</asp:ListItem>
        <asp:ListItem>German</asp:ListItem>
    </asp:CheckBoxList></td></tr>
                        <tr>&nbsp;</tr>
                    <tr><td>&nbsp;</td><td>
                        <asp:Button ID="btnsubmit" runat="server" Text="Submit"/></td></tr>
    </table>

Keep the below given Jquery in between Head Tag (Select minimum Two Language):

   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript" language="javascript">
            $(document).ready(function () {
                $('#btnsubmit').click(function () {
                    //validate only for one value
                    //if ($('#chklanguage input:checked').length > 0)
                    if ($('#chklanguage input:checked').length > 1) {
                        return true;
                    }
                    else {
                        alert('Select atleast two Language')
                        return false;
                    }
                })
            });
</script>

Run the project and check the result.

Is it helpful?


If yes post your comment to admire my work. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget