I’ve been thinking more about the textarea counter issue that I mentioned in my previous post (“Users Paste Differently“).
First of all, I noticed that some of the textarea counter scripts date back to at least 2000, so this has been a problem that developers have been looking to solve for 8 years. I checked the HTML 5 specification and found that in HTML 5, the textarea element has a maxlength attribute. Presumably user agents will build in the most elegant solution.
But what is the current most elegant solution?
I checked a couple sites that I know use textarea counters well: Delicious and Twitter.
I like Twitter’s “warning track” that lets the user know they need to keep it concise and wrap it up, although I find it confusing that they used bright red to denote both the “dangerously close to” as well as “over” the limit. The positive bright red numbers could easily be misconstrued as over the limit, since red is a color we frequently use to denote errors.
Twitter’s counter responds to onBlur and onChange, whereas the counter in Delicious is triggered by neither.
Both get one thing right that I think most other textarea counters get wrong: they don’t truncate the user’s text. Deleting something that the user has typed (or pasted) is definitely a bad idea for at least two reasons: the user may not realize the input was truncated and may submit incomplete info, and that the user, upon discovering that the input requires editing, may choose to cut text from someplace other than the end. Instead, both versions alert the user that they are over the limit and provide information on how many characters need to be cut to stay within the limit.
(As an aside, one thing I find curious is that both count an Enter keystroke as one character. I’ve run into issues with this before because a line break on a Windows-based system should insert 2 ASCII characters: a Carriage Return (CR) and a Line Feed (LF). *nix systems, including OS X, will insert a Line Feed (LF). However, I haven’t been able to reproduce this issue with recent testing. If it is still an issue, I imagine they handle this on the back-end by converting the CRLF to LF before inserting it into the database?)
In short, my recommendations are:
- Don’t truncate the user’s input; let the user correct it
- Let the user know how far over the limit he or she is
- onBlur and onChange should also trigger the counter, in case the user is pasting text
- Keep the counter message simple and clear
Another idea I had for a visual counter:
Aside from turning red once past the limit, though I’m not sure how it would visually convey to the user by how much the text exceeds the limits.
How can a counter be implemented programatically?
<textarea name="example" id="example"></textarea>
<div id="example_counter">300 characters maximum</div>
The main drawback of this approach, I think, is its abuse of HTML standards. The textarea element has no maxlength attribute in HTML 4 (although you could probably extend XHTML to include such an attribute). Likewise, I don’t like the misuse of the label element as the container for the counter.
i like this.
It is intresting. I like the last one. I wish i could download it and stuff..
I display a counter which counts the characters as the text is entered.
However, the problem comes in when the Textarea data is actually saved to a database field. Then, when the data is re-displayed, after a successful save, the character counter is now wrong because of the newline characters.
I thought about trying to include the newline characters in the count, but the initial try slowed down data entry considerably.
Anybody actually saving the data and from the Textarea and showing the person who did the data entry the character count after saving. (Most of the uses I’ve seen for character counters are fire-and-forget with no edit option.)
I do think it may be a little confusing to users that pressing the enter key counts as 2 characters. I suppose I could convert them all to LFs and insert them into the database that way.
You just inspired me to create a jQuery plugin with the specifications you recommended. I didn’t do anything about the Enter key counting as 2 characters, though – I agree that it would be confusing to users.
Could you suggest something that would return character count for special characters which are multibyte and newline and carriage return too.