There are several ways to achieve this. Here you can use the HTML oninput() levelup event, which occurs immediately after changing an element and calling a function.
<input id="myinput" type="text" oninput="sample_func()" /> <button id="change">Change value</button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
.
var input = $("#myinput"); function sample_func(){ alert(input.val()); } $('#change').click(function() { input.val(input.val() + 'x'); });
Or is it jQuery, an input thing (just related to the above example).
<input id="myinput" type="text" /> <button id="change">Change value</button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
.
var input = $("#myinput"); input.on("input", function() { alert(input.val()); }); $('#change').click(function() { input.val(input.val() + 'x'); });
You can also use javascript setInterval() , which constantly works with a given time interval. This is only optional and better if you are running a time-related program.
<input id="myinput" type="text" /> <button id="change">Change value</button> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
.
var input = $("#myinput"); setInterval(function() { ObserveInputValue(input.val()); }, 100); $('#change').click(function() { input.val(input.val() + 'x'); });
rhavendc
source share