Skip to content Skip to sidebar Skip to footer

Cannot Read Property 'getelementbyid' Of Undefined

I have this function to do a filter by jquery, and it is returning this error: Cannot read property 'getElementById' of undefined function VerificaCheck() { var input, filt

Solution 1:

getElementById is available on the document, not on tr.

Documentation

change the following line to

var tipoProduto = document.getElementById("tipoProduto").value;

However, this may not get what you want, based on my guesses that you have multiple elements by this id in your table. Post your html and what you are trying to do, may be there's another way to do this.

UPDATE:

As suspected, your td repeats in the loop, so you multiple td with same id. I'd suggest to remove id from it. Since the value you are looking is the last td, what you can possibly do to get the value you are looking for is (one way that is):

td[td.length-1].innerHTML

So the loop would look more like:

for (i = 0; i < tr.length; i++) {
        td = tr[i].getElementsByTagName("td")[filtro];

        if (td) {
            var tipoProduto = td[td.length-1].innerHtml;

            if (tipoProduto == $('#Produtos').prop("checked")) {
                tr[i].style.display = "";
            } else {
                tr[i].style.display = "none";
            }
        }
    }

Post a Comment for "Cannot Read Property 'getelementbyid' Of Undefined"