<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
function ValidateCheckBox()
{
var selectedCheckBoxesValue = '';
$('#ValidateCheckBox').find("input:checkbox.CheckBoxClassName:checked").each(function (i, selected) {
if (selectedCheckBoxesValue.length == 0) {
selectedCheckBoxesValue += $(selected).val();
}
else {
selectedCheckBoxesValue += ',' + $(selected).val();
}});
// Here you also get all the comma separated values if you want else use below method for it
if(selectedCheckBoxesValue.length == 0)
{
alert("Select atleast one checkbox");
}
}
</script>
</head>
<body>
<div id="ValidateCheckBox" style="background-color:#0099FF; color:#FFFFFF; width:190;">
<table width="200" cellspacing="2" cellpadding="2">
<tr>
<td><input type="checkbox" class="CheckBoxClassName"></td>
<td><label>Checkbox 1</label></td>
</tr>
<tr>
<td><input type="checkbox" class="CheckBoxClassName"></td>
<td><label>Checkbox 2</label></td>
</tr>
<tr>
<td><input type="checkbox" class="CheckBoxClassName"></td>
<td><label>Checkbox 3</label></td>
</tr>
<tr>
<td><input type="checkbox" class="CheckBoxClassName"></td>
<td><label>Checkbox 4</label></td>
</tr>
<tr>
<td><input type="checkbox" class="CheckBoxClassName"></td>
<td><label>Checkbox 5</label></td>
</tr>
<tr>
<td colspan="2"><input type="button" onClick="ValidateCheckBox();" value="Validate checkbox"></td>
</tr>
</table>
</div>
</body>
</html>
Related Posts : .Net,
jquery
0 comments:
Post a Comment
Share your thoughts here...