Auto-suggest/complete

$search_input.keyup(function(e) { clearTimeout(timer); //var original_html = $suggestions_list.html(); var q = $(this).val(); // only makes requests if you have 3 or more characters and press only letter keys if (q.length >= 3 && (e.keyCode != 27 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40 && e.keyCode >= 48 && e.keyCode <= 111 && e.keyCode != 13 || e.keyCode == 8)) { timer = setTimeout(function() { $.ajax({ url: "/ajax/action/search-suggestions", type: "POST", dataType: "html", data: "q="+q, success: function(response) { if (response !== "") { $suggestions_list.html(response); } else { $suggestions_list.empty(); } } }); }, 250); } if (q.length < 3) { $suggestions_list.empty(); } });
Make ajax requests in real time for typed string and return respective HTML

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.