This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Retrict copy from a text field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Retrict copy from a text field" Watch "Retrict copy from a text field" New topic

Retrict copy from a text field

Albin Jose

Joined: Feb 11, 2008
Posts: 11
I have a form in which i have two text boxes one for entering email and the other for verify email (to make sure the user entered the correct email id we are asking to enter the same email id twice),I need to restrict copy feature in both the fields (that is the user should not be able to copy text data from the email and confirm email text boxes) , are there any properties for text box using which i can do this or should i try using java script,I tried using some key press functions but it din work , can you suggest me some method in which this can be achieved
Albin Jose

Joined: Feb 11, 2008
Posts: 11
I am using the following methods , they work for IE but not for mozilla,

1.<body ondragstart="return false" onselectstart="return false">

function preventCopyPaste() {
var key = String.fromCharCode(event.keyCode).toLowerCase();
if ((event.ctrlKey && (key == "c" || key == "v")) ||
(event.shiftKey && event.keyCode==45)) {
event.returnValue = false;
function preventRightClick(){
var rightClick=false;
if(event.which) rightClick=(event.which==3);
if(event.button) rightClick=(event.button==2);
if(rightClick) alert("Right click restricted");

But this doesn work for mozilla, any other option,

Thanks ,
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I cannot give you much help. Your solution seems very Windows centric, but maybe that is okay. I mostly wanted to point out that you would also have to check for Ctrl+Insert and Shift+Insert combinations as well. My vote is that this is not a very user friendly interface.

- Brent
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15376
It does not work in Mozilla because you are not detecting keypress events correctly. Just type in JavaScript keycode into Google and you should find examples on correct detection.

soma lingam

Joined: Apr 26, 2007
Posts: 19
try this for a while may be it should work

function preventPaste(theTextArea){
theTextArea.onpaste = function (){
return false;
Albin Jose

Joined: Feb 11, 2008
Posts: 11
Thanks all of you
jQuery in Action, 2nd edition
subject: Retrict copy from a text field
Similar Threads
Disable Copy/Paste in a Textbox
check whether the text box is filled with value or not
SQL Exception:General Error
Sending a message from a sender's email id to receivers email id without authentication