Solved

Text Entry Field: Type-in YES, Paste-in NO

Posted on 1998-12-30
9
128 Views
Last Modified: 2010-04-09
Is there a way to create a text entry field on an HTML page that will let a user type into it, but not let them cut and paste text from elsewhere into it?

The reason I ask this is that I am trying to set up a game
site.  The game rewards speed and I don't want people to
type their answers ahead of time into Wordpad and then just
cut and paste them into the text field.

This might also be useful on chat sites where some users (losers?) have nothing better to do than to cut-and-paste pages of text into the chat window and lock it up until the pasting is completed.

Thanks.
0
Comment
Question by:dslavin
9 Comments
 
LVL 4

Expert Comment

by:rafistern
ID: 1841129
I suppose you could trap the ctrl-v combination in NS4/IE4. However I don't know how.
0
 
LVL 11

Expert Comment

by:mouatts
ID: 1841130
The simple answer is no because the cut and paste feature is controlled by Windows and not the application (ie the browser). In theory it is possible to prevent cut and paste operating when you develop a Windows application but as you have no control over the browser software in use your can't use this method.

The only way I can think that you can actually do this is by running a Java Applet that contains your fields but I suspect that this is what you want. Even then I don't know the java.awt package well enough to be certain that this is possible.

HTH

Steve
0
 
LVL 4

Expert Comment

by:martinag
ID: 1841131
I've managed to catch Ctrl-V in Netscape 4. I'm now working with IE4. Have patience :-)

Martin
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 4

Expert Comment

by:martinag
ID: 1841132
Here it is:

<FORM><INPUT onFocus="selectedField=this"></FORM>
<SCRIPT>
if (window.captureEvents)
  captureEvents(Event.KEYDOWN);
protectedField = document.forms[0].elements[0];
protectedField.onkeyup = keyUp;
protectedField.lastValue = protectedField.value;
function keyUp(e) {
  if (e) {
    // Netscape
    if (e.which == 22) // Ctrl-V in Windows
      e.target.value = e.target.lastValue;
    e.target.lastValue = e.target.value;
  }
  else {
    // Internet Explorer
    if (event.keyCode == 86 && selectedField.lastKey == 17) { // Ctrl-V in Windows
      selectedField.value = selectedField.lastValue;
    }
    selectedField.lastValue = selectedField.value;
    selectedField.lastKey = event.keyCode;
  }
}
</SCRIPT>

Works great in NS4, but since I am no IE-pro it...well....It doesn't work the first time after you load the page and if you press the "V" button multiple times without releasing "Ctrl", it doesn't work.

Note that I don't even try to detect if the user selects Edit | Paste. I think that's impossible.

I think the code for Ctrl-V (or whatever is the keys for Paste) varies on different systems, so if you really want to catch the Paste command, you'll have to check the code on Mac and Unix (they also differs from NS to IE...). And you'll probably have to get a better MSIE routine...

Martin
0
 
LVL 2

Author Comment

by:dslavin
ID: 1841133
Seems like there are some possible answers (or at least workarounds.)
0
 
LVL 2

Author Comment

by:dslavin
ID: 1841134
MARTINAG:

Please answer the question so I can award you the points.  Thanks for all your efforts!
0
 
LVL 4

Accepted Solution

by:
martinag earned 100 total points
ID: 1841135
Answered.

Martin
0
 
LVL 2

Author Comment

by:dslavin
ID: 1841136
Thanks for the thoroughness of your answer.  Even if it is not a complete solution for every browser (and modified browser where users have remapped the PASTE key) it is a great starting point.
0
 
LVL 4

Expert Comment

by:martinag
ID: 1841137
I just came to think of this solution (it could be causing troubles for speedy typers, though):
You could use a timer with an interval of something like 10 milliseconds. Every time it goes off, you check the length of the field's value. If it differs with more than 1 (or some other low value, like 2 or 3) from the length of the saved value, insert the old value. Save value and reset timer.

Maybe you want me to write a script like that?

Martin
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to Left-Align Navigation bar? 4 26
jquery - show / hide div depending on day and time 19 46
hosting images 4 27
MouseOver help for Intranet website 2 22
Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now