Home » » select all checkbox jquery

select all checkbox jquery

Written By 1 on Monday, September 5, 2011 | 6:43 PM

select all checkbox jquery
//include js file

<script type="text/javascript" src="jquery-1.4.4.js"></script>

<script type="text/javascript">

jQuery(document).ready(function() {

    jQuery('a#select_all').click(function(){

        var obj    = jQuery('select.select').find('option').each(function() {

            jQuery(this).attr('selected', true);

        });        

    });

    jQuery('input[type="checkbox"]#checkbox_all').click(function(){

        if(jQuery(this).attr('checked')){

            jQuery('input[type="checkbox"].chk').each(function(){

                jQuery(this).attr('checked', true)

            });        

        }else{

            jQuery('input[type="checkbox"].chk').each(function(){

                jQuery(this).attr('checked', false)

            });                

        }

    

    });

});

</script>

</head>



<body>





<table border="1" width="200px" rules="groups">

    <tr>

        <th>

        <select name="select" id="select" class="select" multiple="multiple" size="5" style="widtd:150px;">

        

        </select>

        </th>

        <th><a href="javascript:void(0)" id="select_all" >Select All</a></th>

    </tr>

</table>

<br  />



<table border="1" width="200px" rules="groups">

    <tr>

        <th><input type="checkbox" name="checkbox" id="checkbox_all" /></th>

        <th>Dummy Name</th>

    </tr>

    <tr>

        <td><input type="checkbox" name="checkbox" class="chk" /></td>

        <td>Dummy Name</td>

    </tr>    

    <tr>

        <td><input type="checkbox" name="checkbox" class="chk" /></td>

        <td>Dummy Name</td>

    </tr>    

    <tr>

        <td><input type="checkbox" name="checkbox" class="chk" /></td>

        <td>Dummy Name</td>

    </tr>    

    <tr>

        <td><input type="checkbox" name="checkbox" class="chk" /></td>

        <td>Dummy Name</td>

    </tr>    

    <tr>

        <td><input type="checkbox" name="checkbox" class="chk" /></td>

        <td>Dummy Name</td>

    </tr>    

    <tr>

        <td><input type="checkbox" name="checkbox" class="chk" /></td>

        <td>Dummy Name</td>

    </tr>    

    <tr>

        <td><input type="checkbox" name="checkbox" class="chk" /></td>

        <td>Dummy Name</td>

    </tr>   

    

</table>

0 Comment:

Post a Comment