Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect paste in input box

I have a input box, and I would like to use vbscript or javascript (no jquery) to capture the paste event.

like image 958
Itay.B Avatar asked Mar 27 '11 16:03

Itay.B


People also ask

How do I stop copy paste input field?

The onpaste attribute lets us prevent pasting into the form. Adding the autocomplete attribute as well as preventing drag and drop into the element. If you want to avoid the on{event} code in the HTML, you can do it the cleaner way: myElement.


2 Answers

Use the onpaste event to capture the event and do what you need in Javascript. E.g. to disable the paste in an input text field:

<input type="text" onpaste="return false;" /> 
like image 190
philant Avatar answered Sep 23 '22 13:09

philant


Javascript supports onpaste:

http://www.quirksmode.org/dom/events/cutcopypaste.html

like image 40
Jared Farrish Avatar answered Sep 23 '22 13:09

Jared Farrish