Disabling copy option

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Albin
    New Member
    • Mar 2008
    • 3

    Disabling copy option

    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 u suggest me some method in which this can be achieved.

    I want it to work in both IE and Mozilla

    I tried certain stuff which works in ie but not in mozilla .
    can some one help??

    1.[HTML]<body ondragstart="re turn false" onselectstart=" return false">[/HTML]

    2.
    [CODE=javascript]function preventCopyPast e() {
    var key = String.fromChar Code(event.keyC ode).toLowerCas e();
    if ((event.ctrlKey && (key == "c" || key == "v")) ||
    (event.shiftKey && event.keyCode== 45)) {
    event.returnVal ue = false;
    }
    }
    function preventRightCli ck(){
    var rightClick=fals e;
    if(event.which) rightClick=(eve nt.which==3);
    if(event.button ) rightClick=(eve nt.button==2);
    if(rightClick) alert("Right click restricted");
    }[/CODE]

    But this doesn work for mozilla, any other option,

    Thanks ,
    Albin.
    Last edited by gits; Mar 13 '08, 11:44 AM. Reason: added code tags
  • mrhoo
    Contributor
    • Jun 2006
    • 428

    #2
    Clear the value and the defaultValue for both inputs when the first box gets focus.

    When the second box gets focus, check the value in the first, make the first box readOnly, and make the defaultValue of the second box the first character from the first box.

    With each keypress, match the input's value against it's default value.
    If you pasted more than one character, it won't match.
    If it matches, add the next character from the first text to the defaultValue of the second. If one letter at a time is correctly typed in, the defaultValue will match the input value on each keypress.

    On blur or onchange, validate that the defaultValue matches the text in the second input, or notify the user that he must retype both fields, remove the readOnly and focus on the first to clear the values.

    Comment

    Working...