Compare the value of a column with the checkbox

1

I'm trying to compare the value of a column of a table , so depending on what is selected, show or hide the field, I got in this code:

            td = tr[i].getElementsByTagName("td")[3];
            console.log(td);
            debugger;
            if (td == $('#Produtos').prop("checked",true)) {
                    tr[i].style.display = "";
                } else {
                    tr[i].style.display = "none";
            }

But it is not filtering, how to correct? no console.log(td) is appearing <td>True</td> according to each line, am I getting the value wrong?

    
asked by anonymous 16.10.2018 / 22:06

2 answers

1

After talking about the comments of the question we can get the following solution =)

// Criar uma var boolean
var tdBoolean = $(td).text() == "True" ? true : false;

// modificar a checagem para 
if( tdBoolean == $('#Produtos').prop("checked") )
// if (td == $('#Produtos').prop("checked",true))
// isso porque o $('#Produtos').prop("checked",true)
// estava marcando o checkbox
    
19.10.2018 / 22:40
1
            td = tr[i].getElementsByTagName("td")[3];
            console.log(td);
            debugger;

            var valorTd = (td == "True" ? true : false);

            if (valorTd  == $('#Produtos').is(":checked")) {
                    tr[i].style.display = "";
                } else {
                    tr[i].style.display = "none";
            }
    
16.10.2018 / 22:37