In this post I am going to demonstrate how to the check box are <em>checked</em> or unchecked with single check box.
<code><SCRIPT language="javascript">
$(function(){
$("#selectall").click(function () {
$('.myOption').attr('checked', this.checked);
});
$(".case").click(function(){
if($(".myOption").length == $(".myOption:checked").length) {
$("#selectall").attr("checked", "checked");
} else {
$("#selectall").removeAttr("checked");
}
});
});
</SCRIPT>
<strong>HTML:</strong>
</code>
<pre title=""><input type="checkbox" id="selectall"/></pre>
<pre title=""><input type="checkbox" value="2" class="myOption"></pre>
<pre title=""><input type="checkbox" value="1" class="myOption"></pre>
<code><SCRIPT language="javascript">
$(function(){
$("#selectall").click(function () {
$('.myOption').attr('checked', this.checked);
});
$(".case").click(function(){
if($(".myOption").length == $(".myOption:checked").length) {
$("#selectall").attr("checked", "checked");
} else {
$("#selectall").removeAttr("checked");
}
});
});
</SCRIPT>
<strong>HTML:</strong>
</code>
<pre title=""><input type="checkbox" id="selectall"/></pre>
<pre title=""><input type="checkbox" value="2" class="myOption"></pre>
<pre title=""><input type="checkbox" value="1" class="myOption"></pre>
No comments:
Post a Comment