var NoItems = "No items has been found"; var timeout; function Search(elm) { var inputString = elm.val(); var id = elm.attr("id"); if(inputString.length == 0)//if user erases value of the field we need to hide Suggestions and erase hidden fields { elm.val(""); if ($("#suggestions").exists()) { $("#suggestions").fadeOut('fast', function (){$(this).remove()}); } } else { var req = new Subsys_JsHttpRequest_Js(); req.onreadystatechange = function() { if (req.readyState == 4) { var arr = req.responseJS.Suggestions; if (arr) { if (!$("#suggestions").exists()) { $('').insertAfter("#"+id); } $("#suggestions").fadeIn(); if(arr.length > 0) { var s = 1; var text = ''; } else { text = '
'+NoItems+'
'; } $('#suggestionsList').html(text); } } } req.caching = true; req.open('POST', 'ajax.php', true); req.send({ Action: "Suggest", String: inputString}); } }