tags:

views:

53

answers:

4

I first used the onKeyUp event to detect input changes in a textbox. However, when the user enters in a French character using ALT+Num, the event doesn't detect the change until i enter the next character...

Which event should I be using to detect the special character changes. I've tried onChange but does not seem to be working.

I've tried using onkeypress event because I notice that it triggers it after i release the ALT key, however even though once the ALT is release, the onkeypress is triggered and you see the accented character, but when I use this.value for the inputbox, it only registers up to and before the new ALT+Num character is input.

for example: i entered vidé, but the search would not dynamically find vidé, but only vid because the é has not been saved in the - this.value yet, until another key event is triggered.

Hence I was wondering if there's way to simulate/send a key press to trigger it.

A: 

There's a reference at http://unixpapa.com/js/key.html which might be a good idea to have a look at, and according to section 2.1, ALT should generate a keydown and keyup in modern browsers..

I would suggest you use jQuery or a similar library to ease the issues you're facing cross-browser. Have a look at http://jsfiddle.net/qvDbu/1/ for a proof of concept which works fine.

Keypress is not triggered by only modifier-presses, so that's probably the way to go, it allows you to pick up the character entered as well, rather then which key is pressed. Edit: Seems to not be the case in Fx that keypress is triggered by modifiers, but I'm not able to reproduce actually loosing any characters.

Alexander Sagen
http://jsfiddle.net/c5FvH/2/Here's the brief demonstration of what I did... when you type in the top input box, the value is duplicated on the second box.. if you enter in alt+num in the top, you'll see the second is not updated until another key is pressed. how to fix that..
jenn
also i've tried this: http://jsfiddle.net/c5FvH/4/ with all the other key events, but still same.. the alt+num doesn't get saved until another key is pressed.
jenn
In Chrome and Fx on linux, on your first example, the second input is always one behind, the keypress is triggered before the new character is appended to value, regardless of modifiers. Fx triggers an extra keypress when i simply press-and-release a modifier however. So not able to reproduce your exact problem.. Framework ftw.
Alexander Sagen
Your second example works fine in both browsers for me. Exact copy regardless of modifiers. I'm on a norwegian keyboard which has alt gr+num goodness. Same thing I reckon? Not able to use left alt for anything useful
Alexander Sagen
A: 

use keyup. The new character will not be added until the user releases the ALT key and at that point the keyup event will fire.

lincolnk
+1  A: 

You need to bind onkeypress, which won't fire until you finish entering the alt code.

http://jsfiddle.net/c5FvH/

Robert
i've tried that.. but the only problem is the new character entered in is not saved in this.value until another key is pressed. I'm making a dynamic search, as user enters in character the list updates
jenn
here's an example of what i did: http://jsfiddle.net/c5FvH/4/
jenn
Well, the events are firing, just the value isn't what you'd expect it to be. You can test by adding a `console.log('fired');` to the event.
Robert
A: 

FINALLY FIGURED IT OUT!! :D

here's the code, however the String converting event.which code does not work on the jsFiddle though, nonetheless the code works :)

http://jsfiddle.net/qvDbu/30/

jenn