Re: Limit entry into TextArea
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Limit entry into TextArea

From: Thomas 'PointedEars' Lahn <PointedEars@web.de>
Date: Tue Jan 31 2006 - 22:44:56 CET

impaler wrote:

> JohnSouth wrote:
>> In a TextBox I can set a maximum size for the entry.
>> Is there a way of limiting the number of characters being entered into
>> a TextArea control?
>>
>> John South
>> www.wherecanwego.com
>
> <textarea onkeypress="if (this.value.length > 200) this.value =
> this.value.substr(0, 200);">
> </textarea>
>
> do this on onblur too, to avoid copy paste and if there are other
> scenarios to put more too.

Why not limit length of input in the first place?

<textarea onkeypress="return (this.value.length <= 200);"></textarea>

where the parens are not necessary. This should be extended to tell
the user why the number of characters is limited.

PointedEars
Received on Tue Feb 7 21:29:21 2006