tags:

views:

163

answers:

1

I am having difficulty capturing the backspace key as a keyboard Event in javascript/jQuery. In Firefox, Safari, Opera, Chrome, and on the iPhone/iPad, I capture a keyup event on a text input box like this:

$(id_input).keyup(function(event) {
   that.GetHints($(this).val().trim(), event, fieldName);
});

This event captures user keystrokes, then sends them to a function to issue an ajax lookup call.

My problem comes when a user wishes to backspace over a character he/she already typed. In all the browsers to which I have access except for my Droid phone, when I press the backspace key, this keyup event captures the value returned by $(this).val().trim() and sends it on to process in function GetHints. On the Droid, however, neither this keyup nor an equivalent keydown event fires until the user backspaces over every character in $(this).

So, for example, if I type "cu" then backspace over the "u" leaving only "c" in the input field, in all browsers except Droid, the keyup event will fire and call function GetHints("c", event, fieldName). On the Droid, the keyup event never fires.

What am I missing? How/why does this backspace key, on either the soft keyboard or the hard keyboard, on my Droid not function as expected? How do I work around this?

Thanks for your help in advance. Peace! Jeff Falter

A: 

Jeff,

Sorry to say, this is not a solution but a commiseration. I'm having the same issue. I have a zip code field that validates the value on key up. When the user is 'building' a potential zip code, everything works fine. Less than 5 digits will not validate. I also have accounted for a user 'deconstructing' an existing entered zip code with the delete key. If the value is reduced to less than 5 digits, it will 'un-validate'. (validation in this instance means enabling the submit button). However, this bit doesn't work on the Samsung Moment I'm using as an Android test phone.

Delete is detected once the field is empty. For instance, if the user enters the digits 1 through 5, then begins deleting them, the key up event is detected after the 1 is deleted. Why this is, I have no idea. It doesn't help me, because the user is allowed to submit a less than 5 digit number as a zip code.

I would LOVE to see an answer to this issue.

studiobl