Solved

catch paste event?

Posted on 2001-07-05
2
902 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now