How to detect textarea or input type="text" editing?
- by kavoir.com
I use this snippet to prevent the user from accidentally navigating away from the editing page:
var warning = false;
window.onbeforeunload = function() {
if (warning) {
return '';
}
}
Now I want to set the variable warning to be true if any of the textarea or input type="text" has been modified, I want to use the onkeyup event such as in:
document.getElementById('textarea_id').onkeyup = function() {
warning = true;
}
But it's not working. Don't quite want to use jQuery on this. Any insights?