<script type="text/javascript"> $(document).keypress(function(e){ $('#search').val($('#search').val().replace(/[^a-z]/, '')); $.post('source.php', {queryString: ""+$('#search').val()+""}, function(data) { if (data.length > 0) { $('#suggest').show().html(data); } }); }); var arr = new Array(); $(document).keydown(function(e){ var $hlight = $('#suggest li.hlight'), $el = $('#suggest li'); if (e.keyCode == 40) { $hlight.removeClass('hlight').next().addClass('hlight'); if ($hlight.next().length == 0) { $el.eq(0).addClass('hlight') } $('#search').val($('li.hlight').text()); } else if (e.keyCode === 38) { $hlight.removeClass('hlight').prev().addClass('hlight'); if ($hlight.prev().length == 0) { $el.eq(-1).addClass('hlight'); } $('#search]').val($('li.hlight').text()); } if ((e.keyCode == 13 || e.keyCode == 188) && $('#search').val().length > 0) { if (arr.indexOf($('#search').val()) === -1) { $('#search').val($('#search').val().replace(/\,/i, '')); arr.push($('#search').val()); } $('#search').val(''); $('#suggest').hide(); } $('#tags').html(''+arr); }); </script>
...z jednym wyjatkiem.
Działa na takie zasadzie, ze jesli wpisze 'an' powinno mi wyszukac "poland", "holland", "andora" itd. a wyszukuje wszystkie wyrazy w ktorych wystepuje "a".
Nastepnie jak wpisze 'and', wyszykuje mi wszystkie wyrazy z 'an'
Nie wiem w czym problem. Samo zapytanie do bazy jest na zasadzie LIKE "'%'.$queryString.'$'".
Problem tkwi prawdopodobnie w funkcjach js keyPress/Up/Down, ale nie jestem pewien czy napewno to to.