A web developer's blog. PHP, MySQL, CakePHP, Zend Framework, Wordpress, Code Igniter, Django, Python, CSS, Javascript, jQuery, Knockout.js, and other web development topics.

Check Multiple Checkboxes in one click using jQuery

This is useful if you want to “delete” or “update” multiple rows in a table at the same time. This works like the “Check All Email” in YahooMail.

$(document).ready(function() {
    //check all checkboxes
    $("#check_all_boxes").click(function() {
        $(".mycheckbox").each(function(i){
            $(this).attr("checked","checked");
        });
    });
 
    //uncheck all checkboxes
    $("#uncheck_all_boxes").click(function() {
        $(".mycheckbox").each(function(i){
            $(this).removeAttr("checked");
        });
    });
 
    //reset the search form
    $("#reset_button").click(function() {
        $("#search_form input").each(function(i) {
            //alert($(this).html());
 
        });
    });
 
});

And the HTML Code is:

< input class="mycheckbox" name="a" value="1" type="checkbox" />Number 1
< input class="mycheckbox" name="b" value="1" type="checkbox" />Number 2
< input class="mycheckbox" name="c" value="1" type="checkbox" />Number 3
< a href="#" id="#check_all_boxes">Check All< / a>
< a href="#" id="#uncheck_all_boxes">Uncheck All< / a>
This entry was posted in General and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>