I have a JavaScript library that updates a hidden <textarea> HTML element with some data based on some things.
In my (JavaScript) application I’d like to know when these updates occur without having to go through the existing library code.
I was hoping there was an event for this, but apparently not.
How would I listen for changes of the textarea?
Changes can be as simple as document.getElementById("myTextarea").value = "hello";
EDIT I will be using FireFox only, since this code will only be part of a test suite I’m building.
If you control the Javascript library you mention, I would say the easiest way would be to manually trigger the
changeevent every time you change a field’s value.I think this is how it’s done in JQuery: Events/change Otherwise, a simple
document.getElementById('myTextarea').onchange()might work as well.If you have many calls, you could wrap the changing of the value, and the triggering of the event into a
changeFormElement(id, value)function.This requires, of course, that you can modify every instance of when a textarea is changed. If that is given, this is probably the most elegant way.