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

Wednesday, December 7, 2022

validate input type without the protocol for the url

 We can use jQuery validate to format input URL with a valid URL as shown below


rules: {

    url_field: {

      required: true,

      url: true,

      normalizer: function (value){

                value = value.replace(/^https?:\/\//, '');

                return 'http://' + value;

            }

    }

  }


Cheers

Samitha