从下拉列表中按字母顺序选择“最近”选项

I have a list of words in a dropdown and I have a single word that is looking for a suiting partner(user is choosing it) To make this easier for the user(because the list can be very long and the porcess has to be fast) I want to give a possible option.

I already had a look how i van change the selected word.

I want to find the alphabetically "nearest" option but i have no idear how i could find out which word is the nearest neigbore....

I already googled with all words I could think of to get a solution but I couldn´t find something.

Does someone have an idear how i can do it?

If by alphabetically you mean matching letters read from the left, the answer is easy. Simply go through every letter of the word and compare it with the ones in the select drop down. The word that shares the longest starting substring is your "nearest".

The levenshtein function will compute the 'closeness' of 2 string. You could rank the words you have relative to user's string and return the string with the lowest value.

have a look at this library, it contains Fuzzy string matching functions for javascript, including stemming, lehvenstein distance and metaphones: http://code.google.com/p/yeti-witch/

The simplest (and probably fastest) thing in javascript is finding (by binary search) where to put the word in sorted array of your option words using < and > string operators.

For more advanced and precise results, use Levenshtein distance