{"id":147,"date":"2013-04-15T13:42:23","date_gmt":"2013-04-15T18:42:23","guid":{"rendered":"http:\/\/kurtzenisek.com\/articles\/?p=147"},"modified":"2013-08-13T13:42:50","modified_gmt":"2013-08-13T18:42:50","slug":"protect-text-within-textarea","status":"publish","type":"post","link":"https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/","title":{"rendered":"Protect Text within Textarea"},"content":{"rendered":"<p>This exact code protects text in a textarea that was present before editing &amp; should remain at the beginning of the text area. In the case of @ mentioning someone, you could have the text box include that text (and be a 1:1 representation of what will be posted) while preventing it from being deleted by the user.<\/p>\n<p><code>originalText = jQuery('textarea').val();<br \/>\njQuery('textarea').on('change keydown keyup blur',function(){<br \/>\ncurrentText = jQuery('textarea').val();<br \/>\nif(currentText.indexOf(originalText) === -1 &amp;&amp; currentText.indexOf(originalText.substring(0,originalText.length-1)) !== -1) \/\/ If it's just the last character that got deleted (via backspace)<br \/>\njQuery('textarea').val(currentText+originalText.substring(originalText.length-1,originalText.length)); \/\/ Add that character back<br \/>\nelse if(currentText.indexOf(originalText) === -1) \/\/ If it's no longer there<br \/>\njQuery('textarea').val(originalText+currentText); \/\/ Add it back to the front<br \/>\n});<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This exact code protects text in a textarea that was present before editing &amp; should remain at the beginning of the text area. In the case of @ mentioning someone, you could have the text box include that text (and be a 1:1 representation of what will be posted) while preventing it from being deleted [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"episode_type":"","audio_file":"","podmotor_file_id":"","podmotor_episode_id":"","cover_image":"","cover_image_id":"","duration":"","filesize":"","filesize_raw":"","date_recorded":"","explicit":"","block":"","itunes_episode_number":"","itunes_title":"","itunes_season_number":"","itunes_episode_type":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-news"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Protect Text within Textarea - Kurt Zenisek<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Protect Text within Textarea - Kurt Zenisek\" \/>\n<meta property=\"og:description\" content=\"This exact code protects text in a textarea that was present before editing &amp; should remain at the beginning of the text area. In the case of @ mentioning someone, you could have the text box include that text (and be a 1:1 representation of what will be posted) while preventing it from being deleted [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/\" \/>\n<meta property=\"og:site_name\" content=\"Kurt Zenisek\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/kzeni\" \/>\n<meta property=\"article:published_time\" content=\"2013-04-15T18:42:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-08-13T18:42:50+00:00\" \/>\n<meta name=\"author\" content=\"Kurt\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kurt\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/protect-text-within-textarea\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/protect-text-within-textarea\\\/\"},\"author\":{\"name\":\"Kurt\",\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/#\\\/schema\\\/person\\\/f3528f54a8466c58edb0533fcb1c2ec9\"},\"headline\":\"Protect Text within Textarea\",\"datePublished\":\"2013-04-15T18:42:23+00:00\",\"dateModified\":\"2013-08-13T18:42:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/protect-text-within-textarea\\\/\"},\"wordCount\":60,\"commentCount\":0,\"articleSection\":[\"News\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/protect-text-within-textarea\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/protect-text-within-textarea\\\/\",\"url\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/protect-text-within-textarea\\\/\",\"name\":\"Protect Text within Textarea - Kurt Zenisek\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/#website\"},\"datePublished\":\"2013-04-15T18:42:23+00:00\",\"dateModified\":\"2013-08-13T18:42:50+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/#\\\/schema\\\/person\\\/f3528f54a8466c58edb0533fcb1c2ec9\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/protect-text-within-textarea\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/protect-text-within-textarea\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/protect-text-within-textarea\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Protect Text within Textarea\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/#website\",\"url\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/\",\"name\":\"Kurt Zenisek\",\"description\":\"Assorted Code Snippets &amp; Articles\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/#\\\/schema\\\/person\\\/f3528f54a8466c58edb0533fcb1c2ec9\",\"name\":\"Kurt\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d243c95df571db785649246aa036b5c16c30e9dc0dbcf2fc24297b1a5d6eebd8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d243c95df571db785649246aa036b5c16c30e9dc0dbcf2fc24297b1a5d6eebd8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d243c95df571db785649246aa036b5c16c30e9dc0dbcf2fc24297b1a5d6eebd8?s=96&d=mm&r=g\",\"caption\":\"Kurt\"},\"sameAs\":[\"http:\\\/\\\/kzeni.com\",\"https:\\\/\\\/www.facebook.com\\\/kzeni\",\"https:\\\/\\\/x.com\\\/KZeni\"],\"url\":\"https:\\\/\\\/kurtzenisek.com\\\/articles\\\/author\\\/kzeni\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Protect Text within Textarea - Kurt Zenisek","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/","og_locale":"en_US","og_type":"article","og_title":"Protect Text within Textarea - Kurt Zenisek","og_description":"This exact code protects text in a textarea that was present before editing &amp; should remain at the beginning of the text area. In the case of @ mentioning someone, you could have the text box include that text (and be a 1:1 representation of what will be posted) while preventing it from being deleted [&hellip;]","og_url":"https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/","og_site_name":"Kurt Zenisek","article_author":"https:\/\/www.facebook.com\/kzeni","article_published_time":"2013-04-15T18:42:23+00:00","article_modified_time":"2013-08-13T18:42:50+00:00","author":"Kurt","twitter_misc":{"Written by":"Kurt","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/#article","isPartOf":{"@id":"https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/"},"author":{"name":"Kurt","@id":"https:\/\/kurtzenisek.com\/articles\/#\/schema\/person\/f3528f54a8466c58edb0533fcb1c2ec9"},"headline":"Protect Text within Textarea","datePublished":"2013-04-15T18:42:23+00:00","dateModified":"2013-08-13T18:42:50+00:00","mainEntityOfPage":{"@id":"https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/"},"wordCount":60,"commentCount":0,"articleSection":["News"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/","url":"https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/","name":"Protect Text within Textarea - Kurt Zenisek","isPartOf":{"@id":"https:\/\/kurtzenisek.com\/articles\/#website"},"datePublished":"2013-04-15T18:42:23+00:00","dateModified":"2013-08-13T18:42:50+00:00","author":{"@id":"https:\/\/kurtzenisek.com\/articles\/#\/schema\/person\/f3528f54a8466c58edb0533fcb1c2ec9"},"breadcrumb":{"@id":"https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/kurtzenisek.com\/articles\/protect-text-within-textarea\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kurtzenisek.com\/articles\/"},{"@type":"ListItem","position":2,"name":"Protect Text within Textarea"}]},{"@type":"WebSite","@id":"https:\/\/kurtzenisek.com\/articles\/#website","url":"https:\/\/kurtzenisek.com\/articles\/","name":"Kurt Zenisek","description":"Assorted Code Snippets &amp; Articles","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kurtzenisek.com\/articles\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/kurtzenisek.com\/articles\/#\/schema\/person\/f3528f54a8466c58edb0533fcb1c2ec9","name":"Kurt","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d243c95df571db785649246aa036b5c16c30e9dc0dbcf2fc24297b1a5d6eebd8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d243c95df571db785649246aa036b5c16c30e9dc0dbcf2fc24297b1a5d6eebd8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d243c95df571db785649246aa036b5c16c30e9dc0dbcf2fc24297b1a5d6eebd8?s=96&d=mm&r=g","caption":"Kurt"},"sameAs":["http:\/\/kzeni.com","https:\/\/www.facebook.com\/kzeni","https:\/\/x.com\/KZeni"],"url":"https:\/\/kurtzenisek.com\/articles\/author\/kzeni\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/p2Xgc6-2n","_links":{"self":[{"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/comments?post=147"}],"version-history":[{"count":3,"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/posts\/147\/revisions\/162"}],"wp:attachment":[{"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kurtzenisek.com\/articles\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}