Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 915
  • Last Modified:

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.
0
xz02
Asked:
xz02
1 Solution
 
nimaigCommented:
I don't think there is any event handler for paste.
Try using onKeyUp event.
0
 
ozymandiasCommented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now