adsense

Friday, December 16, 2022

Detect input text box change

 We can use jQuery to identify input text change as shown below. This method uses setTimeout and clearTimeout to force the change event fire only after user finishes typing.

JS

var timer;
$("#title").on("input", function(e) {
  var textValue = $(this).val();
  if ($(this).data("lastvalue") != textValue ) {

    $(this).data("lastvalue", textValue );
    clearTimeout(timer);

    timer = setTimeout(function() {
      //code to handle change
      console.log(textValue);
    }, 500);
  };
});
HTML
<script src="jquery.min.js"></script>
<input type="text" id="title">

Cheers

Samitha

No comments:

Post a Comment