Back to Snippets
Searchable Select Dropdown JS
A replacement for a long select element, with a filter box sitting at the top of the option list.
The native select is hidden and a div stands in for it. That swap is what makes the search box possible, since you cannot place an input inside a real dropdown. Typing filters by substring and the list redraws on each keystroke.
Arrow keys and Enter work, and clicking outside closes it. For lists running into the thousands, filter server side and feed the results in, because this compares against every option on every keypress.
452