• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Textarea length

 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe use the the onChange handler instead of onKeyPress?
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is onchange not working ? Show us what you're doing exactly.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
onblur, but he said "b4 he leaves teh field", which in clear means "before he leaves the field"
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic