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 Textarea length 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 "Textarea length" Watch "Textarea length" New topic
Author

Textarea length

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
I have a text area and I need to enforece max length for it. I have the following code on the key press event




when I copy a bunch of text and paste this JS doesn't work.......any alternative ? pls help
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Maybe use the the onChange handler instead of onKeyPress?


Ping & DNS - updated with new look and Ping home screen widget
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
onChange doesn't work...it doesn't validate the lenght at all when I enter the text..I need to stop the user from entering or pasting b4 he leaves teh field .pls advice
[ September 25, 2006: Message edited by: Mary Cole ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Why is onchange not working ? Show us what you're doing exactly.


[My Blog]
All roads lead to JavaRanch
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
onblur="if(this.value.length>200){alert("Your input was too long. It was trimmed to fit.");this.value=this.value.substring(0,200);}"

Make sure you validate this on the server since it can be bypassed with a little knowledge of JavaScript.

Eric
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

onblur, but he said "b4 he leaves teh field", which in clear means "before he leaves the field"
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

b4 he leaves teh field .pls advice


Mary Cole, "b4" "teh" and "pls" are not words. Please refrain from using such abbreviations in your posts and use real words. Please read this for more information.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Textarea length
 
Similar Threads
JavaScript alphanumeric validation
JDBC input parameter for type IS TABLE OF VARCHAR2
Problem with brute Force
problem in validating text area max length
Limited Document JTextField