{"id":103,"date":"2008-11-10T15:52:50","date_gmt":"2008-11-10T20:52:50","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=103"},"modified":"2008-11-15T20:16:08","modified_gmt":"2008-11-16T01:16:08","slug":"users-paste-differently","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2008\/11\/users-paste-differently\/","title":{"rendered":"Users Paste Differently"},"content":{"rendered":"<p><figure id=\"attachment_104\" aria-describedby=\"caption-attachment-104\" style=\"width: 100px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/osric.com\/chris\/accidental-developer\/wp-content\/uploads\/2008\/11\/paste.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/osric.com\/chris\/accidental-developer\/wp-content\/uploads\/2008\/11\/paste.jpg\" alt=\"Paste\" title=\"paste\" width=\"100\" height=\"177\" class=\"size-full wp-image-104\" \/><\/a><figcaption id=\"caption-attachment-104\" class=\"wp-caption-text\">Paste!<\/figcaption><\/figure> I&#8217;ve been using a relatively generic Javascript textarea counter for several years to restrict the input length on form textareas. I&#8217;m not sure where the specific version I&#8217;m using came from, but you can <a href=\"http:\/\/www.google.com\/search?q=textarea+counter\">find dozens like it on Google<\/a>.<\/p>\n<p>Almost all of them rely on the <em>onKeyDown<\/em> and <em>onKeyUp<\/em> 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&#8230;until today.<br \/>\n<!--more--><br \/>\nNaturally, when I tried to enter text into the textarea, I just typed it there. But that&#8217;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&#8217;s text that they have composed once, but are submitting to several different sites. Or maybe it&#8217;s some reason I can&#8217;t even fathom!<\/p>\n<p>When I copy-and-paste text, I highlight it, hit CTRL-c, put my cursor at the destination, and hit CTRL-v. But that&#8217;s not always what users do either. And as it turns out, if you right-click and select Paste, neither <em>onKeyDown<\/em> or <em>onKeyUp<\/em> are triggered. Adding <em>onBlur<\/em> and <em>onChange<\/em> seem to do the trick, though.<\/p>\n<p>Of course, this discovery hasn&#8217;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.<\/p>\n<p>I haven&#8217;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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been using a relatively generic Javascript textarea counter for several years to restrict the input length on form textareas. I&#8217;m not sure where the specific version I&#8217;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. &hellip; <a href=\"https:\/\/osric.com\/chris\/accidental-developer\/2008\/11\/users-paste-differently\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Users Paste Differently<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[38,350,37],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-forms","tag-javascript","tag-textarea"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":5,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":130,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/103\/revisions\/130"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}