2006.01.26

Created 2006-01-27 / Edited 2006-01-27

I wrote my first useful stand-alone javascript thingie! I've always wanted a combo drop-down in HTML... and for one project I'm currently working on it was especially appropriate. Yet again I set out accross the web to look for the perfect fit, but didn't find what I wanted.

But I've been doing this whole Javascript thing quite a bit lately, so I thought I'd give it a whirl. Using behaviour.js to attach events cleanly, I whipped up my very own DHTML Combo. Then I realized that it didn't work quite right.

Simple problem really. My combo is literally a textbox and a listbox. The listbox is normally hidden, but when the textbox gets focus I display the listbox. Then if you mess with the listbox it gets focus. Problem: when the list gets focus, the textbox loses focus first. Normally when the textbox loses focus I want to hide the list again. But not if they are actually trying to maniplate the list!

No problem though, I did a quick little setTimeout timer to reverse the events. Now when the textbox loses focus it waits a bit and then checks to see if the list is the thing that got the focus. If not it hides the list. Seems to work pretty well. Using ies4linux to test (wine+ie all downloaded magically and working rocks) it even works in IE!

Maybe I should put it on JSAN.