File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
Author

Retrict copy from a text field

Albin Jose
Greenhorn

Joined: Feb 11, 2008
Posts: 11
Hi,
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
Greenhorn

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">


2.
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 ,
Albin.
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
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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.

Eric
soma lingam
Greenhorn

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
Greenhorn

Joined: Feb 11, 2008
Posts: 11
Thanks all of you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrict copy from a text field
 
Similar Threads
Sending a message from a sender's email id to receivers email id without authentication
check whether the text box is filled with value or not
XML,dom
Disable Copy/Paste in a Textbox
SQL Exception:General Error