• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Disable Paste operation in textfield

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to disable Paste operation in a text field in html. I tried some solutions but didn't get foolproof solution and which works across all the browsers. Can anybody help me in this?

Thanks
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I personally would not block the users normal commands. If they tyoe there password wrong, then they are an idiot...

What you would have to do is onfocus get the leneght, count key strokes, and on blur determine if the initial length plus keystrokes equal the value that is there.

Eric
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eric Pascarello:

What you would have to do is onfocus get the leneght, count key strokes, and on blur determine if the initial length plus keystrokes equal the value that is there.

Eric




Eric,

Will there not be any problem for backspace and del key being pressed?
I think he has to manipulate key strokes properly, like reducing count on backspace or del key only if the character is actaully deleted.

But I think he can do this.
onfocus - keep the current value in a javascript global variable.
check if ctrl key and V is pressed. if yes, then set back the textbox value to global variable.
And finally he might need to disable right click on the textbox so that user does not paste using right click context menu.


Last but not least

try Googling.


Correct me if I am wrong.
[ March 24, 2006: Message edited by: Dilip Kumar Jain ]
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All I can say what if JavaScript is disabled, all of this is defeated. Let the person paste....lol

Eric
 
sanker san
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies.

I can track the keys and take care of Ctrl+V. The user can still use the Paste option in the Edit menu of the browser and accomplish a paste operation. Is there any way to track this?
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you intent upon ticking off your users?
 
sanker san
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The intention is not to tick off users; but to make sure that the user enters the right value in the text field. The scenario is as follows.

There are two text fields; first one for entering the "Unique Id" and the second one to reenter the "Unique ID" entered in the first text field. We do not want the user to copy the text and paste into the second text field. I'm looking for a way to stop the user from pasting into second text field.
 
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic