I am writing a telephone formatting event handler. Currently my function works on the "onKeyUp" event. It checks the string, strips out unwanted characters and rewrites the value of the element. It does this after each "KeyUp", but this creates problems (see last paragraph if you want details)
I'd rather use the "onKeyPress" event and check the value of the key pressed. I tried this, but I was not able to prevent the value of the key from being outputted when it didn't pass the formatting. The javascript flush() function is used for outputting HTML, not flushing the keyboard buffer. So that didn't work. Any ideas here???
For example: Let's say the user wants to change the 3rd and 4th characters (out of 10 characters). After the first change, the function is called and it will rewrite the phone number, placing the cursor at the end of the text box. Then the user has to use his arrow keys or mouse to move the cursor to the next number he wishes to change. This is a bit tedious for the user.
I'd rather use the "onKeyPress" event and check the value of the key pressed. I tried this, but I was not able to prevent the value of the key from being outputted when it didn't pass the formatting. The javascript flush() function is used for outputting HTML, not flushing the keyboard buffer. So that didn't work. Any ideas here???
For example: Let's say the user wants to change the 3rd and 4th characters (out of 10 characters). After the first change, the function is called and it will rewrite the phone number, placing the cursor at the end of the text box. Then the user has to use his arrow keys or mouse to move the cursor to the next number he wishes to change. This is a bit tedious for the user.