Tuesday, June 14, 2011

Bulk select or deselect of check boxes using JQuery

 Javascript code,

    function selectBulk(mode, option){
        var obj = null;
        switch(mode){
        case 0:
                $("[name=empid[]]").attr('checked', option);  break;
        case 1:
                obj = $("[name=empid[]]:checked");
                $("[name=empid[]]").attr('checked', option);
                obj.attr('checked', !option);
                obj = null;
                break;
        }  
    }

HTML code will be,

    Select <a href="#" onclick="selectBulk(0, true)">All</a> | <a href="#" onclick="selectBulk(0, false)">None</a> | <a href="#" onclick="selectBulk(1, true)">Invert</a>

Output:
        
              Select All | None | Invert

No comments:

Post a Comment