Users Paste Differently

Paste
Paste!
I’ve been using a relatively generic Javascript textarea counter for several years to restrict the input length on form textareas. I’m not sure where the specific version I’m using came from, but you can find dozens like it on Google.

Almost all of them rely on the onKeyDown and onKeyUp events to trigger the script. However, some users still manage to submit text that exceeded the limits, even though the application required Javascript. I could not for the life of me reproduce this issue…until today.

Naturally, when I tried to enter text into the textarea, I just typed it there. But that’s not always what users do. Can you imagine, some users might actually compose text in, say, Microsoft Word and then paste it into a textarea? Maybe they are taking advantage of the spell-checker or grammar-checker. Maybe it’s text that they have composed once, but are submitting to several different sites. Or maybe it’s some reason I can’t even fathom!

When I copy-and-paste text, I highlight it, hit CTRL-c, put my cursor at the destination, and hit CTRL-v. But that’s not always what users do either. And as it turns out, if you right-click and select Paste, neither onKeyDown or onKeyUp are triggered. Adding onBlur and onChange seem to do the trick, though.

Of course, this discovery hasn’t exactly solved the problem: the script we are using simply truncates text that is too long. In Firefox, if your textarea has a scrollbar, it could show the user just the top portion of his or her pasted text. Everything would look OK, and the character count displayed would show, for example, 500 of 500 characters.

I haven’t written a replacement script yet, but something clearly needs to alert the user that text has been truncated. At least, however, I have identified the problem.

2 thoughts on “Users Paste Differently”

  1. I have no idea how long it has been there, but most browsers seem to support an onPaste event, which makes client-side checking for textarea value lengths much more robust.

    The server-side check is still necessary in case the user has disabled Javascript or is using a browser that does not support the onPaste event.

Leave a Reply

Your email address will not be published. Required fields are marked *