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

  • 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.
1 Solution
I don't think there is any event handler for paste.
Try using onKeyUp event.
You can catch the ctrl-v key stroke like this :

<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");
<input type="text" onKeyDown="checkKeyDown()" onKeyUp="checkKeyUp()">


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.

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