wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 41079
    
  43
Maybe use the the onChange handler instead of onKeyPress?


Ping & DNS - my free Android networking tools app
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: 60766
    
  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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Textarea length
 
Similar Threads
JavaScript alphanumeric validation
Problem with brute Force
Limited Document JTextField
problem in validating text area max length
JDBC input parameter for type IS TABLE OF VARCHAR2