Solved

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

Posted on 1998-12-30
9
126 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
Comment Utility
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
Comment Utility
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
Comment Utility
I've managed to catch Ctrl-V in Netscape 4. I'm now working with IE4. Have patience :-)

Martin
0
 
LVL 4

Expert Comment

by:martinag
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Author Comment

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

Author Comment

by:dslavin
Comment Utility
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
Comment Utility
Answered.

Martin
0
 
LVL 2

Author Comment

by:dslavin
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

772 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

10 Experts available now in Live!

Get 1:1 Help Now