The jQuery .change() event does not .change() second time the user types and press Enter to select an item. It works for the first time.
See: http://jsfiddle.net/CtXbU/
If you focus on the list and type AD and press Enter, [EDIT], a warning appears. But if you type AG and press Enter, nothing will happen. A warning appears only when you click on a button from the list.
What should I do if I want the user to change the list using both the mouse and the keyboard?
I know that I can use .keypress() to handle keyboard events, but it is strange to have two separate sections of code that do the same.
Is there one jQuery event that will process mouse and keyboard changes as soon as they appear?
Thanks!
** UPDATE **
This may clarify my question: http://jsfiddle.net/Bybr2/2/
// How can I create an event (or handler) that // (a) fires AS SOON AS keypress is invoked from user keyboard input // (b) also fires AS SOON AS change is invoked from user mouse input // (c) does not fire a second time when change is invoked after keypress, when the user clicks away following keypress?
change after pressing a key can be very confusing - this happens only when the user presses Enter or presses, so if I make changes on the client side, the user can be very surprised!
The only solution I can think of is some kind of variable like user_has_just_done_keypress , which is set to true when the key is pressed, and then reset to false in the next change event, but it seems very dirty, It would also not work if you had a change from mouse to change from user reconfiguration. Argh!
source share