catch paste event?

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.
xz02Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ozymandiasConnect With a Mentor Commented:
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
 
nimaigCommented:
I don't think there is any event handler for paste.
Try using onKeyUp event.
0
All Courses

From novice to tech pro — start learning today.