Skip to content

Instantly share code, notes, and snippets.

@micmath
Created February 2, 2010 11:50
Show Gist options
  • Save micmath/292604 to your computer and use it in GitHub Desktop.
Save micmath/292604 to your computer and use it in GitHub Desktop.
<html>
<head>
<script>
function init () {
var el = document.getElementById ("textarea");
if (el.addEventListener) { // Firefox, Opera and Safari?
el.addEventListener('textInput', onTextInput, false); // Safari?
el.addEventListener('input', onTextInput, false); // FF?
el.addEventListener('propertychange', onTextInput, false);
}
}
function onTextInput (event) {
if (event.data) {
console.log("event.data: " + event.data);
}
else if (event.target && event.target.value) {
console.log("event.target.value: " + event.target.value);
}
else if (event.propertyName && event.propertyName.toLowerCase() === 'value') {
console.log("event.srcElement.value: " +event.srcElement.value);
}
}
window.onload = init;
</script>
</head>
<body>
<textarea id="textarea">Textarea</textarea>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment