I have a JavaScript library that updates an HTML element hidden <textarea> with some data based on some things.
<textarea>
In my (JavaScript) application, I would like to know when these updates happen without having to go through the existing library code.
I was hoping there was an event for this, but apparently not.
How do I listen to text box changes?
Changes can be as simple as document.getElementById("myTextarea").value = "hello";
document.getElementById("myTextarea").value = "hello";
EDIT I will only use FireFox, as this code will only be part of the test suite that I am creating.
Javascript, , , - change .
change
, JQuery: Events/change document.getElementById('myTextarea').onchange().
document.getElementById('myTextarea').onchange()
, changeFormElement(id, value).
changeFormElement(id, value)
, , , . , , , .
, , , , , IE, , , . onpropertychange.
onpropertychange
textArea.onpropertychange = function () { if (event.propertyName == "innerText") alert('innerText has changed.'); }
, , , , . - , , . , , , , .
FireFox value:
value
HTMLTextAreaElement.prototype.__defineSetter__("value", function(t) { alert('someone is setting the value of a textarea'); return this.textContent = t; });
DOM , node node.value; API JavaScript , .
EDITED: Firefox? , , , . . , "" , . , , , . . .
var textnode = document.createElement('textarea'); textnode.watch('value', function(attr, oldv, newv){ alert(newv); return newv; // you have to return correct value back. }); //and now trigger the change to see that this works. textnode.value = 'Bla';
, ?:)
, , :
var oldVal, el; function setTimer(){ setTimeout(function(){ if(el.value != oldVal){ console.log('something happened'); oldVal = el.value; } setTimer(); }, 5000); };
.
: textarea , "innerHTML",
textarea
innerHTML
document.getElementById("myTextarea").innerHTML = "hello";