I want to make live search using jQuery AJAX and PHP, with one input textbox as the filter of the data. So on the background I have JSON data like this:
[
["1","Your Name 1","button_field"],
["2","Your Name 2","button_field"],
["3","Your Name 3","button_field"]
]
This is my jQuery code, for the live search when user start typing on the textbox:
$('input[name="search_value"]').on('keydown', function() {
$.ajax({
url: 'http://localhost/myapp/ajax/get',
type: 'GET',
dataType: 'json',
success: function(data) {
var search = $('input[name="search_value"]').val();
var output = '';
for (i = 0; i < data.length; i++) {
if (($.inArray(search, data[i]) !== -1) || (search === '')) {
output += '<tr>';
for (j = 0; j < data[i].length; j++) {
output += '<td>' + data[i][j] + '</td>';
}
output += '</tr>';
}
}
$('.table-data > table > tbody').html(output);
}
});
});
I try to using search, by typing Your Name 2
, and it works. But when I try to typing your name 2
(no uppercase for each first word) and try to typing our name 2
(with missing y
), the result is not shown.
And my question is : How to make the search results is ignoring the uppercase (make case insensitive) and start showing the data even the search value is incomplete ? Thanks for all your answers :)