Disable Paste and Drag event

K

khng

How to disable the copy/drag event for some selected textfield as I
want the user to key in instead of copy or drag the required
information.

For IE, I done it with the onPaste and onDragEnter Event, but it don't
work on Other Browser, so I need your helping hand
 
T

Touffy

How to disable the copy/drag event for some selected textfield as I
want the user to key in instead of copy or drag the required
information.

You can't disable copy/paste. So you'll have to implement that another way.

You can do it by watching keypress and onchange events.

If the value of your input element changes without enough keys having
been pressed, you'll know some characters weren't typed. For example,
with an onkeypress event handler, you could increment a counter
(decrement it for delete key, don't change for arrow keys, etc). Inside
an onchange handler, compare that counter with how many characters were
added to the value since the last onchange. If the number seems
reasonable (don't be too strict though, if only 5 keys were pressed to
input a 7-char-long string, maybe some events were just skipped or
something...), then these chars were probably typed in the hard way.

This rough method will also block auto-completing forms, and maybe some
voice recognition software as well.

I'm curious, why do you want your users to forsake the wondrous
facilities offered by their OS and endanger their precious wrists ?
 
K

khng

Touffy said:
You can't disable copy/paste. So you'll have to implement that another way.

You can do it by watching keypress and onchange events.

If the value of your input element changes without enough keys having
been pressed, you'll know some characters weren't typed. For example,
with an onkeypress event handler, you could increment a counter
(decrement it for delete key, don't change for arrow keys, etc). Inside
an onchange handler, compare that counter with how many characters were
added to the value since the last onchange. If the number seems
reasonable (don't be too strict though, if only 5 keys were pressed to
input a 7-char-long string, maybe some events were just skipped or
something...), then these chars were probably typed in the hard way.

This rough method will also block auto-completing forms, and maybe some
voice recognition software as well.

I'm curious, why do you want your users to forsake the wondrous
facilities offered by their OS and endanger their precious wrists ?

Thanks you your suggestion...

But for some field, e.g.the email field I want the user to type it
manually instead of copy or drag
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top