Solved

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

Posted on 1998-12-30
9
129 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

809 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