2

this question has been made in several places but I have not found a great answer. I want to detect an input (text) value change. The value is changed via pure javascript with no frameworks (I can't access this) so the solution can't be modify the val() function of jquery to trigger an event. Event's wont work as you know. The only solution that actually works is

setInterval(function() { ObserveInputValue($('#input_id').val()); }, 100);

but I want to find something different without using a setInterval

Raidel
  • 61
  • 1
  • 4

2 Answers2

0

As David Thomas says, changing the value via javascript doesn't fire the onchange event... Therefore your javascript function needs to call the element.onchange() event once it has completed.

Tony Duffill
  • 239
  • 1
  • 5
-3

You can write your own JavaScript function to listen to onChange() event using jQuery and then monitor if the value has changed or not.

The Code using JavaScript is as follows:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<input type="text" id="checkThis" placeholder="Enter Something Here...">

<script type="text/javascript">
      $("#checkThis").on("change", function() {
        // Press `F12` on Chrome or `Ctrl+Shift+S` on Firefox to view output in browser console
        console.log($(this).val());
      });
</script>
Abhay Bh
  • 147
  • 2
  • 15