I have this table.
<input id="emp_search" />
<input id="search" type="button" value="search" />
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>number</th>
<th>letters</th>
<th>Gender</th>
<th>Company</th>
</tr>
<tr>
<td>John</td>
<td>Lennon</td>
<td>151</td>
<td>sf</td>
<td>Male</td>
<td>Corp (Technologies)</td>
</tr>
<tr>
<td>Paul</td>
<td>McCartney</td>
<td>753</td>
<td>tj</td>
<td>Male</td>
<td>Corp (Services)</td>
</tr>
<tr>
<td>George</td>
<td>Harrison</td>
<td>24</td>
<td>ge</td>
<td>Female</td>
<td>Corp Technologies</td>
</tr>
<tr>
<td>Ringo</td>
<td>Starr</td>
<td>26</td>
<td>hg</td>
<td>Female</td>
<td>Corp (Help Desk)</td>
</tr>
</table>
when you search exact words like "John Paul" or "John Mccartney", the result should be 2 rows containing the searched word. (now that's the function of my jquery , that you can find multiple words and result to multiple exact result.
Now my problem is , when you searched the words containing with the parenthesis like "SMS Global (Help Desk)." it doesn't even work.
$(function () {
$(' #search ').click(function () {
var str = $('#emp_search').val();
var strary = str.split(' ');
$("table").find("tr").slice(1).each(function (index) {
var text = $.trim($(this).find("td:nth-child(6)").text());
for (var i = 0; i < strary.length; i++) {
console.log("%s:%s", text, strary[i]);
var regex = new RegExp(".*\\b" + strary[i] + "\\b\.*", "gi");
$(this).toggle(regex.test(text));
console.log(regex.test(text));
if (regex.test(text))
break;
}
});
});
});
ok here's an explanation. let's say that the only column that i could search in is the 1st column. where you could type john and paul , which is in the same column. and exact word. so about the sms global (technologies), i will search the sms global (technologies)|sms global (help desk) and will result to two rows containing the word that is searching.
is there something wrong with the code? I don't know these code. I just found it. and I'm trying to practice and understand it. But right now I'm just a new programmer.