Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    May 2003
    Location
    UK
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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!

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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.

  • #3
    New Coder
    Join Date
    May 2003
    Location
    UK
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <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"

  • #5
    New Coder
    Join Date
    May 2003
    Location
    UK
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #6
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.
    Last edited by beetle; 07-11-2003 at 06:15 PM.
    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”

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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"

  • #8
    New Coder
    Join Date
    May 2003
    Location
    UK
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •