Click to See Complete Forum and Search --> : disable paste


idiotbear
10-22-2003, 05:48 AM
hey guys

I'm using a "verify e-mail address" script which makes the visitor enter their e-mail address twice and then checks to see if they match.

Is there any way I can make it impossible for them to paste their addy in so that they HAVE to type it?

Cheers

Rob

clairec666
10-23-2003, 06:07 AM
I shouldn't think so - the pasting function comes from within the computer itself, if you get my meaning
You can't tell with javascript events which way the text was entered, by pasting or by typing
I know this is annoying when needing to verify e-mail addresses, but there isn't much you can do about it

As an afterthought - if the user submitted the form, you could include another page where they have to verify the e-mail
Therefore they wouldn't have remembered to copy it when they were on the last page and there is a large chance they would have typed the whole thing in again

idiotbear
10-23-2003, 06:12 AM
it's actually very possible, as long as you don't mind doing quite a lot of coding ;)

I'm using a series of functions trapped by OnKeyDown and OnMouseDown, to test for right-clicks, the Insert key, and the CTRL key.

If INSERT or CTRL is pressed, I return false - which stops anything else happening.

If the right mouse button is clicked, I call a cross-browser compatible script to disable the right-click context menu, which I thieved from www.dynamicdrive.com (http://www.dynamicdrive.com) .

Then, I use OnBlur to reverse the right-click-disabling function, so it all works nicely everywhere else on the page.

Fun!

Cheers anyway, Claire

R

clairec666
10-23-2003, 06:15 AM
wow :D these things continue to amaze me!
mind if i nick your code?

idiotbear
10-23-2003, 06:19 AM
by all means :D here's the functions:



function checkCtrlIns(field)
{
if (event.ctrlKey==1 || event.keyCode==45)
{
return false
}

else
{
return true
}
}

function browser()
{
if (event.button == 2)


if (navigator.appName == 'Microsoft Internet Explorer')
{ clickIE()
}
if (navigator.appName == 'Netscape')
{ clickNS
}
else
{ clickNS
}


//Disable right click script III- By Renigade (renigade@mediaone.net)
//For full source code, visit http://www.dynamicdrive.com

var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")
}

function reenable()
{
var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return true;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return true;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return true")
}



Then, the form field looks like this:




<input name="email2" type="text" class="formCell" id="Verify E-mail" size="43" autocomplete="off" onKeyDown="return checkCtrlIns(this)" onMouseDown="browser()" onblur = "reenable()">



Enjoy!

idiotbear
10-23-2003, 06:22 AM
except, of course, you don't need the argument in checkCtrlIns - it survived from a previous attempt!

clairec666
10-23-2003, 06:24 AM
Cheers!
Wouldn't it be worth putting a message next to the form reminding users NOT to copy/paste
I can imagine some of the idiots of this world trying an infinite number of times to paste their address, without giving up and typing it in instead?
Just a thought!

idiotbear
10-23-2003, 06:27 AM
I guess it would.

As Einstein once famously said - "There are only two infinite things: the universe, and the ****wittedness of idiotbear's clients." ;-)

clairec666
10-23-2003, 06:29 AM
:D
As found in all decent books of quotations!
Cheers for that script, I gotta go eat now!
All this DHTML talk makes me hungry!

TomDenver
10-23-2003, 04:11 PM
You don't have to use right click, Ctrl or Insert to copy and paste, though. Although most people would use one or more of those. You can select text with left mouse button, hit Edit -->Copy, then move the focus to the next email field, hit Edit -->Paste.

Reminds me of a saying I heard once: Make something idiot proof, and someone will make a better idiot.

Granted, I think your script would stop almost all people from using copy/paste to enter the second email field.

idiotbear
10-24-2003, 03:24 AM
very true. I don't mind too much, as long as I'm vaguely discouraging them...

James L.
10-28-2003, 06:51 PM
...and all that work completely defeated by disabling scripting in the browser...something 13% of web users do!

Ya can't win... can ya!?

idiotbear
10-29-2003, 02:35 AM
how very true. still, it was an interesting exercise.