...by copy paste...
The copy/paste bit is easy on a modern browser: Catch the input
event.
...or programmatically...
There's no event raised when the value of a textarea is changed programmatically. The only way is to use a MutationObserver
watching for subtree
, childList
, and characterData
changes. MutationObserver
is well supported other than in IE, where it didn't arrive until IE11. However, for most purposes, you can use a polyfill that uses the obsolete "mutation events" to provide a barebones MutationObserver
shim. Just search for "MutationObserver polyfill" or "MutationObserver shim" to find options.
To my surprise, setting the value
of a textarea
does not fire a MutationObserver
on Chrome (some other things do, but not that). This means that in order to detect programmatic changes, you'll have to poll (blech!), keeping the old value and periodically (say, every 20-100ms) checking to see if it's different.