My table filter with javascript is not working

I’m doing a project on intellij with springboot and i have a dynamic table. I put a search box and add a script that in theory it has work but it doesn’t.

This is my table with the input box:

<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">
<table id="tablePatients" width="100%" border="1px solid black" >
<tbody id="mytable">
<tr th:each="patient : ${allPatients}">
    <td th:text="${}">1</td>
    <td th:text="${}">w</td>
    <td th:text="${patient.surname}">e</td>
    <td> <a href="show?id=10" th:href="@{show(idPatient=${} , idDoctor=${})}"> show </a></td>
    <td> <a href="addPrescription?id=10" th:href="@{newPrescription(idPatient=${} , idDoctor=${})}"> add prescription </a></td>

This is the script:

    $("#myInput").on("keyup", function() {
        var value = $(this).val().toLowerCase();
        $("#myTable tr").filter(function() {
            $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)

These are the libraries that i imported in the head:

<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>

Can someone please help me to understand what i did wrong?

Yes, the id table was wrong.
Now i fixed it and it does the search but it doesn’t seem work. When I write , it doesn’t find the words, so the script is wrong after all

91 thoughts on “My table filter with javascript is not working”

Leave a Comment