Tuesday, 3 January 2012

jquery Example -Multiple Checkbox Select/Deselect

In this post I am going to demonstrate how to the check box are <em>checked</em> or unchecked with single check box.

&nbsp;
<code>&lt;SCRIPT language="javascript"&gt;
$(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");
        }

    });
});
&lt;/SCRIPT&gt;

<strong>HTML:</strong>

</code>
<pre title="">&lt;input type="checkbox" id="selectall"/&gt;</pre>
<pre title="">&lt;input type="checkbox" value="2" class="myOption"&gt;</pre>
<pre title="">&lt;input type="checkbox" value="1" class="myOption"&gt;</pre>

No comments:

Post a Comment