Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrict copy from a text field

 
Albin Jose
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this for a while may be it should work


function preventPaste(theTextArea){
theTextArea.onpaste = function (){
return false;
}
}
 
Albin Jose
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all of you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic