Wednesday, July 16, 2008

Javascript Life-Saver!

After much trial and head scratching while debugging a custom text input *hint* dropdown (much like the gmail email address hinting) I discovered how to prevent arrow key action without returning the function before the desired time:


   or, rather:

if (document.all) {
} else if (e.cancelable) {

Without this the up and down arrow keys to select hints also move the cursor the beginning or end of the input field (especially in Safari).
I found other (less effective) work-arounds which worked in all browsers except Safari on PC. So this little tid mit was a life saver indeed!
That's it!   It has almost the same effect as "return false;" without ending your script.

Thank you: