Solved

catch paste event?

Posted on 2001-07-05
2
905 Views
Last Modified: 2008-01-09
Hi, how can I catch event that "sth paste into a textbox"?
I tried onchange , but unless I move cursor after doing paste,
it doesnot get triggered.
0
Comment
Question by:xz02
2 Comments
 
LVL 9

Expert Comment

by:nimaig
ID: 6258319
I don't think there is any event handler for paste.
Try using onKeyUp event.
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 50 total points
ID: 6259193
You can catch the ctrl-v key stroke like this :

<html>
<head>
<script language="javascript">
<!--

var ctrlModifier = false;

function checkKeyDown(){
     var keyCode = window.event.keyCode;
     if (keyCode == 17){
          ctrlModifier = true;
     }
}

function checkKeyUp(){
     var keyCode = window.event.keyCode;
     if (keyCode == 17){
          ctrlModifier = false;
     }
     if (keyCode == 86 && ctrlModifier){
          alert("You just pasted");
     }
     //alert(keyCode);
}
//-->
</script>
</head>
<body>
<input type="text" onKeyDown="checkKeyDown()" onKeyUp="checkKeyUp()">

</body>
</html>

Try pasting into this field now.
I'm not sure how you catch the paste from the context menu though. You could always disable it though.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

775 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question