I suspect it's not working because:
on("keydown.autocomplete", ...)
Isn't a valid jQuery event. I think you mean to use
"keydown"
instead. However that's not the only problem, you're calling the
autocomplete()
function inside the event handler, but you actually only need to call it once when the document is ready. The
autocomplete()
function has a property called
minLength
which you can set to restrict auto-completion.
Remove the keydown event handler and call
autocomplete()
directly, and provide the
minLength
property to restrict it.