How to detect textarea or input type="text" editing?
Posted
by kavoir.com
on Stack Overflow
See other posts from Stack Overflow
or by kavoir.com
Published on 2010-04-27T02:16:45Z
Indexed on
2010/04/27
2:23 UTC
Read the original article
Hit count: 220
JavaScript
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?
© Stack Overflow or respective owner