File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes javascript:Restricting the user to paste in textbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "javascript:Restricting the user to paste in textbox" Watch "javascript:Restricting the user to paste in textbox" New topic
Author

javascript:Restricting the user to paste in textbox

Chennarao Marvatu
Ranch Hand

Joined: Aug 09, 2004
Posts: 32
Hello Gurus,
In the Textbox and Textarea there is max length limit.I have validated when the user TYPE more than the max . But when the copy and paste it is allowing.
So i want the user to restrict when he paste the data in the TExtarea or textbox itself .Please suggest me.


mchrao
Keith Sebastian
Greenhorn

Joined: Mar 10, 2005
Posts: 9
For a textbox (element input, type text), maxlength is part of the HTML Specification (link), and is does not even require javascript turned on to properly work. As a test I just tried to copy/paste into a text box with maxlength set, and it didn't paste past the maxlength. Even in a browser as old as Netscape 2.

Now, textareas. That's a different story. If you look at the textarea spec, you'll notice there is no maxlength. If you want to limit characters in a textarea, you'll need to use javascript. Is this where you're having a problem?
[ September 05, 2005: Message edited by: Keith Sebastian ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You could also do something like this too

onchange="if(this.value.length>100)this.value=this.value.substring(0,100);"

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript:Restricting the user to paste in textbox
 
Similar Threads
Capturing values in textbox
Implementing html forms, etc... in Java?
How to make a count down of Characters in a textbox?
Copy-to-clipboard
issue with a textbox on firefox.