Silviu
Silviu

Reputation: 175

Autocomplete from scratch using jquery

I know that stackoverflow is not to do my job, for that I ask for generics advices

E.g

I have :"http://www.imobiliare.ro/sugestii/huned"+ T , T value from input, Information is pass to URL and generate a JSON, after that http://www.imobiliare.ro/sugestii/huned+T+I, TI values from input.

Hard part for me is how to send continuous that information to url without press a submit button, something like every time I pass a value in input text, is read and send automaticali to URL and make a request

I can't use any existing lib.

Upvotes: 2

Views: 1015

Answers (2)

hijarian
hijarian

Reputation: 2228

Here is some starting points for you, which you should already know if you took a task which says "do not use any libraries". Autocomplete "without using any libraries" is wrong design requirement and a waste of time in almost all cases imaginable.

  1. Bind a listener on "keyup" event.
  2. This listener should fire not each time "keyup" is fired, but with delay of ~500 ms, or else you'll be triggering POST requests on each letter entered, and in case of "deoxyribonucleic acid" will be probably overkill.

That's all. You absolutely do not need any "continuous" checking, only key presses.

For "continuous" checking you should use setTimeout and setInterval functions.

EDIT

Here is JsFiddle with the crude solution showing both of my points: you attach an event listener to the text input and then (with proper debouncing mechanics!) on key presses you send a request to your backend API. Everything else is up to your imagination. Usually results are returned into a dropdown list, but I certainly would not reimplement that from scratch.

Upvotes: 2

New_Bee
New_Bee

Reputation: 1

this might help you Building an Autocomplete from scratch with javascript

Upvotes: 0

Related Questions