jeudi 5 mai 2016

Trying to select all checkboxes in a single HTML table in Javascript

I have two separate tables with two separate "select all" checkboxes. I am trying to use that "select all" button to "select all" checkboxes in that single table, not all the checkboxes on the entire page. The following is my attempt at this but the select all function doesn't work. I am new to javascript, so please do not crucify me.

function checkAll() {
    var table = document.getElementById('myTable');
    var inputs = table.document.getElementsByTagName('input'), val = null;
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].type == 'checkbox') {
            if (val == null)
                val = inputs[i].checked;
            inputs[i].checked = val;
        }
    }
} 




Aucun commentaire:

Enregistrer un commentaire