Skip to content

Instantly share code, notes, and snippets.

@L-Soft
Last active September 18, 2019 09:46
Show Gist options
  • Save L-Soft/80d8f38da1f5166d9587e8ac290df308 to your computer and use it in GitHub Desktop.
Save L-Soft/80d8f38da1f5166d9587e8ac290df308 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Selecall Checkbox sample</title>
</head>
<body>
<table bgcolor="#E9E9E9" border="1">
<tr>
<td>
<B>Selectall Sample</B><BR><BR>
<table border='1'>
<tr>
<th><input type="checkbox" id="selectallchkbox"/></th>
<th>TV Brand</th>
<th>Rank</th>
</tr>
<tr>
<td><input class="tvChkBox" type="checkbox" id="tvChkBox1"/></td>
<td>Sony</td>
<td>1</td>
</tr>
<tr>
<td><input class="tvChkBox" type="checkbox" id="tvChkBox2"/></td>
<td>Samsung</td>
<td>3</td>
</tr>
<tr>
<td><input class="tvChkBox" type="checkbox" id="tvChkBox3"/></td>
<td>LG</td>
<td>2</td>
</tr>
<tr>
<td><input class="tvChkBox" type="checkbox" id="tvChkBox4"/></td>
<td>Onida</td>
<td>4</td>
</tr>
</table>
</td>
</tr>
</table>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
/*Handler For SelectAll Checkbox*/
$("#selectallchkbox").change(function(){
$('.tvChkBox').prop("checked",$(this).prop("checked"));
});
/*Handler For rest of the checkbox*/
$('.tvChkBox').change(function(){
if( $('.tvChkBox').length === $('.tvChkBox:checked').length){
$("#selectallchkbox").prop("checked", true);
} else {
$("#selectallchkbox").prop("checked", false);
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment