Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Disable Paste operation in textfield

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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?
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic