asp.net - Capture CopyPasteSelect in Javascript - Stack Overflow

admin2025-04-20  0

How can i capture the following keys in Textbox using JavaScript?

Ctl + a

Ctl + c

Ctl + v

Following is the original Situation.

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

Following is the original Situation.

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.

Share Improve this question edited Apr 13, 2012 at 15:31 Pankaj asked Apr 13, 2012 at 11:39 PankajPankaj 10.1k39 gold badges151 silver badges297 bronze badges 8
  • 1 jQuery: stackoverflow./a/1503425/284240 or stackoverflow./a/238835/284240 or stackoverflow./a/2904944/284240 – Tim Schmelter Commented Apr 13, 2012 at 11:43
  • 1 stackoverflow./questions/2903991/… – Chuck Norris Commented Apr 13, 2012 at 11:44
  • 1 @Tim thanks for the reply. Actually, I need it in Javascript. – Pankaj Commented Apr 13, 2012 at 11:44
  • 3 @PankajGarg: jQuery is nothing else than javascript. – Tim Schmelter Commented Apr 13, 2012 at 11:45
  • @chuck it's answer is in JQuery. – Pankaj Commented Apr 13, 2012 at 11:45
 |  Show 3 more ments

3 Answers 3

Reset to default 6

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745106370a285314.html

最新回复(0)