In our ongoing quest to create the ultimate application, usability and familiarity are often given far too little thought. This article explains a very effective way of giving users a comfortable environment, by mimicking a popular piece of GUI functionality. I will show you how to create a tool that captures characters as you type, and tries to match them to items in a <select> menu. This is a great way to speed up the process of selecting a specific item within a large list, or just suggesting a similar item to what the user has typed.
I have found this little tool to be incredibly handy. For obvious reasons, it saves time when trying to find an item in a list. It also adds to the usability of our application, providing a familiar environment for users. (Not to mention that people are generally pretty impressed by this idea.)
There is another extremely useful purpose for which I've used this tool. I once built a knowledge-base which allowed users to upload and manage documents into certain categories, and administrators could create new categories. To prevent the creation of a bunch of categories with similar but slightly different names, I threw this script into the category creation panel. As administrators would start to type in the name they wanted, the tool would basically say “hey, this category already exists, would you like to just re-use the name?” This prevented having a whole bunch of redundant records in the 'names' table of the database.
I know that menus with a couple hundred records can easily be handled by this script, but once you get into really large menus, you might want to consider modifying the script to make it more efficient. I would perhaps have a global variable that remembers the last thing you typed in, and starts searching the menu items from where you last were, not all the way from the beginning each time. But anyhow, the point of this tutorial is to plant this idea in your mind, and let you modify it to suit whatever need you may come up with. Happy coding!
In case you want all the code, un-broken, here it is:
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.