29 Nov 2007 2:57 AM #1
counting string length in textarea
i have an textarea with maxlength(text).
in an ideal world the user is typing the text directly into this field, if he is one char over maxlength the maxlengthtext is displayed, so far so good.
But most of my users paste text in to this field. If the text is over maxlength, the user sees the error, but doesnt know how many chars he is over the limit.
I think the easiest way would be to display the current and allowed length in the error message.
How could this be achieved ?
Any help would be much appreciated.
29 Nov 2007 11:09 AM #2
29 Nov 2007 11:13 AM #3
Why dont you specify the max length even before the user does anything?
29 Nov 2007 12:25 PM #4
maxlength IS definied. and remember this is an textarea not a textfield. (no html maxsize)
if a user paste in a text with more chars then allowed, the user is getting the error message, but dont know how much chars he is over the limit. This is the only problem i want to come by, in displaying the chars in the textarea field in the errormessage.
eg. "In this field are only 250 chars allowed. Current: 284"
29 Nov 2007 1:27 PM #5
You should be able to specify a custom validation function via the validator config in which you build the message based on how many characters have been entered.
29 Nov 2007 10:08 PM #6
This is more of an event issue then anything else. Because the user cuts & pastes into the field, there isn't any events thrown to check with. The only suggestion that I'd have for this is to set a blue vent listener to check for the maxlength as well, and if it's over, mark the field as invalid and show the error message. It's a little bit longer to do, but it'll do what you want it to.'Once again, fortune vomits on my eiderdown'
- Edmund Blackadder