Because only the last function of the addEventListener method of my script is working. I'm developing filters on a DataTable that when I click the fetch button it filters the information into the table. The filter functions are working, but only works individually.
HTML:
<label for="proto">Protocolo</label>
<input type="text" class="form-control" name="proto" id="proto"
placeholder="Pesquisar...">
<label for="nome">Nome</label>
<input type="text" class="form-control" name="nome" id="nome"
placeholder="Pesquisar...">
<label for="doc">Documento</label>
<input type="text" class="form-control" name="doc" id="doc"
placeholder="Pesquisar...">
<button class="btn btn-primary btn-block" id="btnBuscar">Buscar</button>
Script:
function proto() {
var proto, filter, table, tr, td, i;
proto = document.getElementById("proto");
filter = proto.value.toUpperCase();
table = document.getElementById("table");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
function nome() {
var nome, filter, table, tr, td, i;
nome = document.getElementById("nome");
filter = nome.value.toUpperCase();
table = document.getElementById("table");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[3];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
function doc() {
var doc, filter, table, tr, td, i;
doc = document.getElementById("doc");
filter = doc.value.toUpperCase();
table = document.getElementById("table");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[4];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
document.getElementById("btnBuscar").addEventListener("click", function(){
proto();
doc();
nome();
});