I would like to catch the change of a textbox value in JavaScript. Not sure if there is such an event?
And I would like to call my own function when this change happens and pass the new updated text value to my function....
e.g. when user interacts on the website and programatically a textbox value changes, I would like to catch this and read the value and send it to my function, lets assume the function is called updatedText('string value here') and would take a string.
Edit:
I tried the following code, which works fine to read a textbox value (the textbox is on a form element):
var form = document.forms['freqform'];
var freq_input = form.elements[3];
var str = freq_input.value;
alert(str);
This works fine and an alert pops up showing the current value of this textbox.
Now I have added the following code that you recommended in the first link:
freq_input.addEventListener('input', function (evt) {
alert('Function has fired');
});
But the alert box does not fire, when the textbox value was changed by other javascript running on the site. (I am testing it as a snippet in Chrome DevTools)
If I change/shorten it to:
freq_input.addEventListener('input', alert('Function has fired'));
It works, but fires immediately after execution and only once....afterwards it does not fire again when input value changes (I also tried the change event with same effect).
Thanks for your help, I am still abit noobish on JS (normally doing vb.net)