How can i capture the following keys in Textbox
using JavaScript
?
Ctl + a
Ctl + c
Ctl + v
I have three Textboxes
for Phones numbers. Textbox1
max length is 3 , 2nd's is 3 and 3rd is 4. When user types three digits in TextBox1
the cursor moves automatically to TextBox2
same thing happens with TextBox2 as well as TextBox3. I am handling this functionality in keyup event. Now, I am parallely using your code. But it moves in keyup event as well. This case happens when all TextBoxes are filled. Now suppose I am in TextBox1 and presses Ctl + A . This moves the user to third TextBox(unacceptable case). This is the issue.
How can i capture the following keys in Textbox
using JavaScript
?
Ctl + a
Ctl + c
Ctl + v
I have three Textboxes
for Phones numbers. Textbox1
max length is 3 , 2nd's is 3 and 3rd is 4. When user types three digits in TextBox1
the cursor moves automatically to TextBox2
same thing happens with TextBox2 as well as TextBox3. I am handling this functionality in keyup event. Now, I am parallely using your code. But it moves in keyup event as well. This case happens when all TextBoxes are filled. Now suppose I am in TextBox1 and presses Ctl + A . This moves the user to third TextBox(unacceptable case). This is the issue.
Use the select
, copy
and paste
events respectively. Pretty much universally supported these days.
var textBox = document.getElementById("textBoxId");
textBox.onpaste = function() {
alert("paste");
};
Likewise for the other events. Demo here: http://jsfiddle/timdown/EC2Hf/
And what about right click, osx that does not use control, the edit copy option on the browser, the button on my old keyboard, etc?
There is more than just key presses.
That said, most browsers support
oncopy and onpaste events.
You would have to first check if the ctrl button was clicked and then the correspnding letter keys. This link may help you out