jQuery can be used to handle these events on an input text field.
- change (when text input field changes and loses focus)
$('input#field1').on('change', function(evt) { console.log(this.value) }); $('input#field1').change(function(evt) { console.log(this.value) });
- keyup
$('input#field1').on('keyup', function(evt) { console.log(this.value) }); $('input#field1').keyup(function(evt) { console.log(this.value) });
- paste
$('input#field1').on('paste', function(evt) { console.log(this.value) });
Example – input change event
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> Change the following and focus somewhere else<br> <input id=field1 type=text value=10> <div id=msg></div> <script type="text/javascript"> $('input#field1').on('change', function(evt) { $("#msg").append("newval => " + this.value + "<br>"); }); </script>
Example – input change, keyup, paste events
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <input id=field1 type=text value=10> <div id=msg></div> <script type="text/javascript"> $('input#field1').on("change keyup paste", function(evt) { $("#msg").append("eventtype => " + evt.type + " / newval => " + this.value + "<br>"); }); </script>