0

I have JSP page which displays the records fetched from mysql through java servlet. Now I want filter the obtained records using jquery. I used the following code with head section of jsp page

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.0.min.js">
</script><script type= "text/javascript">{$(document).ready(function()
{$("#searchInput").keyup(function() {
    var rows = $("#fbody").find("tr").hide();
    var data = this.value.split(" ");
    $.each(data, function(i, v) {
        rows.filter(":contains('" + v + "')").show();
    });
})})};
</script>

The code for getting the records from servlet and displaying it in the JSP is given below

 <body><input id="searchInput" ><br/>


<TABLE  align="Center" border="1px" width="80%">
<thead>
<tr><th><b>User_ID</b></th>
    <th><b>User_Name</b></th>
    <th><b>Password</b></th>
    <th><b>Designation</b></th>
</tr>
</thead>
    <%Iterator itr;%>
    <%List data=(List) request.getAttribute("UserData");
    for(itr=data.iterator();itr.hasNext();)
    {%>
        <tbody id="fbody">
        <tr>
            <% String s= (String) itr.next(); %> 
            <td><%=s %></td>
            <td><%=itr.next() %></td>
            <td><%=itr.next() %></td>
            <td><%=itr.next() %></td>

            <form id="edit" action="EditRecord" method="post" >
            <td><input type="hidden" name="hidden_edit" id="edit_id" value="<%=s %>"/> 
            <input type="submit" value="Edit" name="edit"> </td>
            </form>

            <td><form id="delete" action="DeleteRecord" method="post" >
            <td><input type="hidden" name="hidden_delete" id="delete_id" value="<%=s %>"/>
            <input type="submit" value="delete" name="delete"> </td>
            </form></td>    
    <%} %>
        </tr>
        </tbody>
</TABLE></body>

I am able to get all the records but the script is not filtering my record. Dont know where is the problem.Could any one help me out please.

3
  • try var rows = $("#fbody").find("tr"); and rows.hide(); afterwards Commented Apr 27, 2014 at 19:46
  • @Timur Thanks for your reply. But could elaborate where should I put the above line afterwards? Commented Apr 27, 2014 at 20:23
  • check the answert from @Abimbole Esuruoso it looks like you are having multiple tbody tags with same id which should not happen. Commented Apr 27, 2014 at 20:26

1 Answer 1

1

Take tbody out of your for loop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.