Since you are talking about 10 checkboxes, so I assume you may be giving some class name to them. So if your class name is chkStyle then you can check this as -
$("[id$=myButtonIDComeHere]").click(function() {
var checkedCount = $(".chkStyle:checked").length;
if (checkedCount == 0 ) {
alert("Select checkbox");
return false;
}
else if (checkedCount == 1 ) {
alert("Select More than 1 CheckBoxes");
return false;
}
});
If you don't have class on these checkboxes then you can use other selector to find the above function to check.
sridevi.vmb
Member
39 Points
130 Posts
validation of checkbox in jquery
Nov 27, 2012 07:35 AM|LINK
want to validate the 10 checkboxes
if none of the checkboxs are clicked show the alert message
or if any one of the checkboxes is checked show the alert message click more than one checkbox
want in jquery only not javascript
me_ritz
Star
9339 Points
1448 Posts
Re: validation of checkbox in jquery
Nov 27, 2012 07:44 AM|LINK
if( $("input:checked").length == 0 ) { alert("none selected"); } else if($("input:checked").length == 1) { alert("select more than one"); }sridevi.vmb
Member
39 Points
130 Posts
Re: validation of checkbox in jquery
Nov 27, 2012 09:23 AM|LINK
want to check whether it is checkbox or not
anil.india
Contributor
2613 Points
453 Posts
Re: validation of checkbox in jquery
Nov 27, 2012 05:08 PM|LINK
Since you are talking about 10 checkboxes, so I assume you may be giving some class name to them. So if your class name is chkStyle then you can check this as -
$("[id$=myButtonIDComeHere]").click(function() { var checkedCount = $(".chkStyle:checked").length; if (checkedCount == 0 ) { alert("Select checkbox"); return false; } else if (checkedCount == 1 ) { alert("Select More than 1 CheckBoxes"); return false; } });If you don't have class on these checkboxes then you can use other selector to find the above function to check.
codepattern.net/blog ||@AnilAwadh
asteranup
All-Star
30184 Points
4906 Posts
Re: validation of checkbox in jquery
Nov 28, 2012 02:36 AM|LINK
Hi,
Try this-
http://jsfiddle.net/asteranup/b2vWP/
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
bruce (sqlwo...
All-Star
37626 Points
5574 Posts
Re: validation of checkbox in jquery
Nov 28, 2012 02:50 AM|LINK
to ignore radio
$('input[type="checkbox"]:checked').length > 0
if you need a subselct of checkboxes, give them a unique class name or data- arg
$('input[type="checkbox"].myclass:checked').length > 0
matifnadeem
Contributor
4966 Points
1155 Posts
Re: validation of checkbox in jquery
Nov 30, 2012 10:28 AM|LINK
Hi sridevi.vmb,
Check this demo and then go back to main page to see the code.
Let me know if query remains...
Cheers
M Atif Nadeem
Mark as Answer if you got right thing
Read my blog | Follow me on LinkedIn