I have a password and confirm password field and I dont want the user to simply copy from the first field and paste in the later field.What should I do for this??
There is no effective way to stop this that works on all browsers. Even if such a solution existed, a user could just disable JavaScript and just copy and paste if desired. Most users won't copy and paste though, as it's for their own benefit and is to prevent mistakes.
Copy functionality is usually disabled for password-type fields, so you don't need to do anything. There is nothing to stop a user pasting the same text into both fields from elsewhere, however, and there isn't a lot you can do about it. Trying to prevent this would stop some users who want to be sure they have their password right from pasting it in, as well as users that use password generators.
Here is a way...
<asp:TextBox ID="txtEMailVerifyJoin" runat="server" ClientIDMode="Static"
autocomplete="off"
onpaste="pasteEvent('reg_conf_email');return false;"
onkeydown="disablePaste('pasteEvent()','reg_conf_email');"
onkeyup="disablePaste('pasteEvent()','reg_conf_email');"
oninput="disablePaste('pasteEvent()','reg_conf_email');"
></asp:TextBox>
And for javascript
<script>
var charCount = document.getElementById("txtEMailVerifyJoin").value.length;
var oldVal = eval(document.getElementById("txtEMailVerifyJoin")).value;
function disablePaste(methodToCall)
{
newCharCount = document.getElementById("txtEMailVerifyJoin").value.length;
oldCharCount = charCount;
charCount = newCharCount;
if(newCharCount - oldCharCount > 1)
{
eval(methodToCall);
charCount = oldVal.length;
}
else
{
oldVal = eval(document.getElementById("txtEMailVerifyJoin")).value;
}
}
function pasteEvent()
{
document.getElementById("txtEMailVerifyJoin").value=oldVal;
return false;
}
function initDisablePaste()
{
charCount = document.getElementById("txtEMailVerifyJoin").value.length;
oldVal = eval(document.getElementById("txtEMailVerifyJoin")).value;
}
initDisablePaste();
</script>
Its not mine idea, if I find where I see it I will post it here.
See it live here: Join Athineon
this command works (for this page) on the Confirm email address ! (not for the password)
About the user interface and if this is a good idea, I make a question here: http://ui.stackexchange.com/questions/1488/wondering-if-i-must-let-a-user-copy-paste-the-double-asking-confirm-e-mail-on-the