0

These lines of code are in a class I cannot change. It changes the value of an input field. NOTE: the input HTML is part of the original DOM. There is no DOM insertion. Just an input value change.

r = document.getElementById('myinputfield');
r.value = '';

I'm trying to catch when the above script is changing the value. This doesn't work. ( My code is loaded before the change event happens.)

r = document.getElementById('myinputfield');
r.addEventListener("change", function(){
    alert('success');
});

When I manually alter the input field value, my code works fine.

Scotty
  • 130
  • 13
  • Take a look to [mutationobserver](https://developer.mozilla.org/it/docs/Web/API/MutationObserver) – gaetanoM Jun 07 '17 at 16:13
  • The input field is part of the original DOM. It's not a insertion by the JavaScript. I don't believe mutationobserver applies. – Scotty Jun 07 '17 at 16:34
  • This was marked as an duplicate based on a assumption instead of asking questions. My question is left unanswered. I'm a bit disappointed. – Scotty Jun 07 '17 at 16:48
  • I found a working answer here: https://stackoverflow.com/questions/16013024/detect-programmatic-changes-on-input-type-text – Scotty Jun 07 '17 at 16:54

0 Answers0