Handling Keyboard in Drop Down List
<p>I am converting values based on units (km to m, lb to g, etc). I have it working, except for one bug that I can't seem to resolve.</p>

<p>Here is the function that handles the events (conversion is happening in a jQuery plug-in):</p>

<pre><code>function unitConversion() {
    var from;

    // Remember which unit was selected in the drop down list.
    $('select.unit').live('click', function () {
        from = $(this).find('option:selected').text();
    });

    // Now handle the conversion.
    $('select.unit').live('change', function () {
        // Get the from and to values.
        // var from = $(this).prev().find('option:selected').text();
        var to = $(this).find('option:selected').text();

        // Change the text for each field that corresponds with this component.
        var textBoxes = $(this).closest('div.data-group').find('input:text');
        textBoxes.each(function () {
            var curValue = $(this).val();
            $(this).val($(this).unitConvert({
                value: curValue,
                from: from,
                to: to
            }));
        });
    });
}
</code></pre>

<p>This works great (although, if you have any improvements to this code, I'm always wiling to learn). However, the original problem I had was that I had to remember the previous selected unit in the drop down list. Hence, the 'click' event that I'm doing.</p>

<p>This solution works great...as long as the individual uses the mouse. However, if I tab onto the drop down list with the keyboard, and press the up/down arrow keys, nothing happens. I have tried the various key* events, and those do not seem to work, either. What should I be doing here to handle keyboard AND mouse input?</p>

<p>(My hope was that the change event would allow me to access the previously selected item, but that doesn't appear to be the case.)</p>

<p><strong>Update</strong>: I wanted to provide some additional clarification.</p>

<p>If I use the focus event, then the conversions get kind of weird. The reason is because I only set the "from" value the first time I get focus. If I want to the conversion to happen correctly every time, I have to lose focus on the drop down list, and then do the process over. Not very useful.</p>

<p>In addition, for whatever reason, when I tab into the field and then click the up and down arrows, the change event does not fire. I really have no idea why that is...</p>
