lundi 3 avril 2017

Selecting checkbox "All" to select all underlying checkboxes in javascript

I have a checkbox with JavaScript but if click checkall, the other checkboxes wont select.What am I missing here?Hope anyone could tell me what went wrong. I must be missing something with JavaScript but really I dont have any idea.I'd already done my research and the best resort to lane on is here.Hope someone could enlighten me here.

    function checkAll(checkname, bx) {
        for (i = checkname.length; i--; )
            checkname[i].checked = bx.checked;
    }
        


    function checkPage(bx){                    
        for (var tbls = document.getElementsByTagName("table"),i=tbls.length; i--; )
            for (var bxs=tbls[i].getElementsByTagName("input"),j=bxs.length; j--; )
               if (bxs[j].type=="checkbox")
                   bxs[j].checked = bx.checked;
    }
  <table border="1" name ="table">

    <tr>
        <td name ="list00">
            <label name ="list00">
                <input type="checkbox" name="Check_ctr" value="yes" onClick="checkAll(document.list00.link, this)"><b>Check All</b><dd>
                <input type="checkbox" name="link" value="something.com">something.com<dd>
                <input type="checkbox" name="link" value="something.com">something.com<dd>
            </label>
        </td>
        <td><label name ="list01">
                <input type="checkbox" name="Check_ctr" value="yes" onClick="checkAll(document.list01.link, this)"><b>Check All</b><dd>
                <input type="checkbox" name="link" value="something.com">something.com<dd>
                <input type="checkbox" name="link" value="something.com">something.com<dd>        
            </label></td>
    </tr>
    <tr>
        <td><label name ="list10">
                <input type="checkbox" name="Check_ctr" value="yes" onClick="checkAll(document.list10.link, this)"><b>Check All</b><dd>
                <input type="checkbox" name="link" value="something.com">something.com<dd>
                <input type="checkbox" name="link" value="something.com">something.com<dd>    
            </label></td>
        <td><label name ="list11">
                <input type="checkbox" name="Check_ctr" value="yes" onClick="checkAll(document.list11.link, this)"><b>Check All</b><dd>
                <input type="checkbox" name="link" value="something.com">something.com<dd>
                <input type="checkbox" name="link" value="something.com">something.com<dd>    
            </label></td>
    </tr>
    </table>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire