Reputation: 6029
Can some one help me out with a code snippet that will allow me to search one column on a html table with the search criteria that has been typed in to a text box? which would be a mobile number i want to be able to search the mobile phone number TD in my table provided below and highlight any matches.....
heres my button and txt box i want to call the jquery off the button click.........
<asp:TextBox ID="txtSearchMobileNumber" runat="server" CssClass="number"></asp:TextBox>
<asp:button runat="server" id="BtnSearchMobile"\>
heres my table
<code>
<table id="HandsetDetails">
<tr>
<td>
Mobile Phone number
</td>
<td>
Network Provider
</td>
<td>
Amount
</td>
</tr>
</table>
</code>
Upvotes: 1
Views: 1848
Reputation: 38147
Use the jQuery highlight plugin
$("#HandsetDetails").highlight(<your keyword(s)>);
then just create a CSS style for your highlighted word(s) :
.highlight {
background-color: #FFFF88;
}
Using highlight with your HTML :
$('#BtnSearchMobile').click(function() {
$("#HandsetDetails").highlight($('#txtSearchMobileNumber').val());
});
or even better you could use DataTables another jQuery plugin that could filter the table depending on input - and a load more !! export to excel / pdf etc
(note - im not connected to either plugin - just hate re-inventing the wheel)
Upvotes: 1