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.
The onchange element could be used on a textarea to launch a script after the user finishes filling in the field. The script could do something like enable the form submit button or enable a follow-up field that shouldn't be completed until the textarea has received input.
Unfortunately, FF does not fire change event for textarea .
$('#textareaID'). on('input change keyup', function () { if (this. value. length) { // textarea has content } else { // textarea is empty } });
Try using the input event.
If you control the Javascript library you mention, I would say the easiest way would be to manually trigger the change
event 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With