Thursday, 22 August 2013

jQuery, how to capture when text input has changed as a result of another event

jQuery, how to capture when text input has changed as a result of another
event

I have a text input that is updated as a result of a button event. I would
like to detect when the value in the text input has changed. See the
example below:
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#text').bind("input change paste", function(){
console.log("text changed");
// do something
});
$('#click').click (function(){
$('#text').val('something');
});
});
</script>
<body>
<input id='text' type='text'>
<input id='click' type='button' value='click'>
</body>
Later on, that button will trigger a calender so the user select a
date/time which will update the text input. Since the calender is part of
a library we I don't want to change it. I would like to detect when the
text field gets a new value.
thanks!

No comments:

Post a Comment