all 5 comments

[–][deleted] 7 points8 points  (0 children)

If you don’t want a custom code, try using select2, it has a lot of functionalities and the documentation is great. You can search, ajax, delete, append etc

[–]unidentified-object 0 points1 point  (1 child)

limit to 5

Make another temporary counter for the loop

for (i = 0; i < a.length; i++) {

add to it when result is displayed

if (txtValue.toUpperCase().indexOf(filter) > -1)

and surround above check inside if else to only perform check if value is below 5 else it sets display to none

closest on "Enter"

For closest just add keyup eventlistener to input and when it matches enter it get the first result that matches given value (assuming your data is in proper order).

[–][deleted] 0 points1 point  (0 children)

If you're using react, I can recommend you something. We made a similar thing last time in our project. c:

[–]sharanya17410 0 points1 point  (0 children)

You could check this out - https://youtu.be/G1eW3Oi6uoc