Your problem is here:
<input type = 'text' name= 'target' id='target' style='width:150px' onblur ='setTimeout('removeSuggestions()', 20);' onkeyup ='getSuggestions(this.value);'/>
For some reason, you use single quotes to surround your attribute values, but then you also use it to surround your function call in setTimout (). Therefore, when the browser parses it, it stops the attribute in
onblur ='setTimeout('
And you get JS errors.
Use double quotes to surround your HTML attributes.
<input type = "text" name= "target" id="target" style="width:150px" onblur ="setTimeout('removeSuggestions()', 20);" onkeyup = "getSuggestions(this.value);"/>
Also, this is not the best way to use setTimout (). Use an anonymous function instead.
In addition, binding inline event listeners is not best practice. Use unobtrusive JavaScript instead.
$(function(){ $('#target').blur(function(e) { setTimeout(function(){ removeSuggestions() }, 20); }); $('#target').keyup(function(e) { getSuggestions(e.target.value); }); });
hope that helps
source share