asp.net - How to create jQuery function to validate custom validator on ASP checkbox list -
here code checkbox
list: data bounded table
<asp:checkboxlist id="cbl_appliancepresent" clientidmode="static" cssclass="cbl_appliancepresent" runat="server" datatextfield="appliance" datavaluefield="applianceid" repeatdirection="horizontal"> </asp:checkboxlist>
here custom validator
:
<asp:customvalidator id="specifyappliances" clientidmode="static" runat="server" enableclientscript="true" errormessage="please select vacant-not secure reasons" font-bold="true" clientvalidationfunction="validatenotsecure" forecolor="red" font-size="small"></asp:customvalidator>
function:
function validatenotsecure(source, args) { var options = $('.cbl_appliancepresent'); (var = 0; < options.length; i++) { if (options[i].checked) { enablevalidator('specifyappliances'); args.isvalid = true; return false; } } disablevalidator('specifyappliances'); args.isvalid = false; }
if u want solved using jquery , without using custom validator here solution.
<body> <form id="form1" runat="server"> <div id="chl1"> <asp:checkboxlist id="checkboxlist1" runat="server"> <asp:listitem>item1</asp:listitem> <asp:listitem>item2</asp:listitem> <asp:listitem>item3</asp:listitem> <asp:listitem>item4</asp:listitem> </asp:checkboxlist> <asp:label id="label1" runat="server" text="" clientidmode="static"></asp:label> <asp:button id="btncheck" runat="server" text="button" clientidmode="static" /> </div> </form> <script type="text/javascript"> $(document).ready(function () { $("#btncheck").click(function () { var = 0; $(":checkbox").each(function () { if (this.checked) { = + 1; } }); if (a == 0) { $("span[id$='label1']").text('please select'); return false; } }); }); </script> </body>
Comments
Post a Comment