Click here to Skip to main content
15,922,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hellooo... i need help, anybody help me for checkbox using javascript?
this is my script:

<!DOCTYPE html>
    <title>jQuery With Example</title>
    <script type="text/javascript">
        $(function () {
            var chkId = '';
            $('.chkNumber:checked').each(function () {
                chkId += $(this).val() + ",";
            chkId = chkId.slice(0, -1);

            $('.chkSelectAll').click(function () {
                $('.chkNumber').prop('checked', $(this).is(':checked'));

    <table id="mytable">
                <input type="checkbox" class="chkSelectAll" />SelectAll
            <td><input type="checkbox" class="chkNumber" value="1" />One</td>
            <td><input type="checkbox" class="chkNumber" value="2" />Two</td>
            <td><input type="checkbox" class="chkNumber" value="3" />Three</td>
            <td><input type="checkbox" class="chkNumber" value="4" />Four</td>
            <td><input type="checkbox" class="chkNumber" value="5" />Five<br /></td>

i want if i checked/unchecked all value 1-5 class(chkSelectAll) is checked/unchecked.

give me solution please...

1 solution

try below
$('.chkSelectAll').change(function () {
    $('.chkNumber').prop('checked', $(this).is(':checked'));

$(".chkNumber").change(function () {
    $('.chkSelectAll').prop('checked', $('.chkNumber:checked').length == $('.chkNumber').length);

Share this answer
Ade.Ruyani.Z 16-May-14 12:04pm    
thank you for your answer but that's not what i mean, i mean if i checked value 1-3, checkbox class(chkSelectAll) still false checked, and if i continue checked checkbox 4-5 that mean value 1-5(all checked), checkbox class(chkSelectAll) is selected checked true. im confuse...please help
DamithSL 16-May-14 12:12pm    
check my update
Ade.Ruyani.Z 16-May-14 12:17pm    
thankyou damithsl, this is work without problem. your great n help me.
DamithSL 16-May-14 12:20pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900