Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-11-2003, 01:08 PM   PM User | #1
michael.hd
New Coder

 
Join Date: May 2003
Location: UK
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
michael.hd is an unknown quantity at this point
Stop cut and paste from textbox

Does anybody know how to stop people cutting and pasting from a text box.
Is it even a javascript thing?

I have a page where I ask users to enter their email address twice - 2nd time to verify no typing mistakes. At the moment they can just cut and paste from one to the other. This makes the whole thing pointless so I would like to stop the ability to do this on the page.

Is it possible and how?

Thank you in advance.
__________________
They only tell you its a stupid question when they don't know the answer!
michael.hd is offline   Reply With Quote
Old 07-11-2003, 03:12 PM   PM User | #2
arnyinc
Regular Coder

 
Join Date: Jan 2003
Posts: 867
Thanks: 4
Thanked 8 Times in 8 Posts
arnyinc is an unknown quantity at this point
Use a key event (onkeydown, onkeypress, onkeyup) and two counters. Then make sure the counters are both positive numbers before submitting (they won't be equal if the user types a backspace or delete). I'm fairly certain the paste will not increment the counters since it isn't a key event.
arnyinc is offline   Reply With Quote
Old 07-11-2003, 04:38 PM   PM User | #3
michael.hd
New Coder

 
Join Date: May 2003
Location: UK
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
michael.hd is an unknown quantity at this point
Thanks for that,

I may have to implement something like that if I can't find what I'm after. It will enable me to check that they didn't cut and paste the address, but what I was after was something that didn't let them do it at all.

I am sure (as sure as I can be) that once I went on a website which wouldn't allow me to highlight the text I had input into the box - so I couldn't copy it and had to re-type it.

That's what I am really after! But if it's not possible I think your suggestion is a workaround.

thanks for the help.
__________________
They only tell you its a stupid question when they don't know the answer!
michael.hd is offline   Reply With Quote
Old 07-11-2003, 05:00 PM   PM User | #4
Vladdy
Senior Coder

 
Join Date: Jun 2002
Location: Nashua, NH
Posts: 1,724
Thanks: 0
Thanked 0 Times in 0 Posts
Vladdy is an unknown quantity at this point
<input onselect="this.blur()" ...
__________________
Vladdy | KL
"Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"
Vladdy is offline   Reply With Quote
Old 07-11-2003, 05:10 PM   PM User | #5
michael.hd
New Coder

 
Join Date: May 2003
Location: UK
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
michael.hd is an unknown quantity at this point
Thanks, but that didn't work either. My text box code is like this..


<input type="text" name="address" size="25" maxlength="40" onselect="this.blur()">

and I can cut and paste using mouse or keyboard - even drag and drop!

Im using IE explorer 6 browser. Could this be part of the problem?
__________________
They only tell you its a stupid question when they don't know the answer!
michael.hd is offline   Reply With Quote
Old 07-11-2003, 05:12 PM   PM User | #6
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
hmmmmm

Let's see, let me count the ways to copy and paste (and this is only Windows!)

1) Ctrl + C | Ctrl + V
2) Ctrl + Ins | Shift + Ins
3) Right-click >> Copy | Right-click >> Paste
4) Select text | Ctrl-drag'n'drop
5) Edit >> Copy | Edit >> Paste

You can't directly prevent #5, and you can possibly do something about 1-4, but not without a lot of headache.

Personally, I don't think it's worth the effort.

If you MUST have a solution, then I can only offer this IE5+ fix

<input type="text" onpaste="event.returnValue=false" ondrop="event.returnValue=false"/>

However, you'll likely make people think you're site is busted and just piss them off. I don't recommend this, but there it is.

And, of course, Mozilla et al., Opera, etc won't be affected by this fix.
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”

Last edited by beetle; 07-11-2003 at 05:15 PM..
beetle is offline   Reply With Quote
Old 07-11-2003, 05:28 PM   PM User | #7
Vladdy
Senior Coder

 
Join Date: Jun 2002
Location: Nashua, NH
Posts: 1,724
Thanks: 0
Thanked 0 Times in 0 Posts
Vladdy is an unknown quantity at this point
damn IE strikes again.... add this:

<input onselect="this.blur()" onselectstart="return false;" .....
__________________
Vladdy | KL
"Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"
Vladdy is offline   Reply With Quote
Old 07-11-2003, 05:44 PM   PM User | #8
michael.hd
New Coder

 
Join Date: May 2003
Location: UK
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
michael.hd is an unknown quantity at this point
Thanks all for your help.

In the end Vladdy it did work - on IE 6.0.


I won't even bother to check other browsers as the weekend is here.

But next week.......
__________________
They only tell you its a stupid question when they don't know the answer!
michael.hd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:25 PM.


Advertisement
Log in to turn off these ads.