Does text input element not have a change event? When I attach a change event handler to a text input it is not being fired. Keyup is fired, but keyup is not sufficient for
You can achieve it:
$(document).ready(function(){
$('#textBox').keyup(function () {alert('changed');});
});
or with change (handle copy paste with right click):
$(document).ready(function(){
$('#textBox2').change(function () {alert('changed');});
});
Here is Demo
I have found that this works:
$(document).ready(function(){
$('textarea').bind('input propertychange', function() {
//do your update here
}
})
$('#input').on("input",function () {alert('changed');});
works for me.
The HTML4 spec for the <input> element specifies the following script events are available:
onfocus, onblur, onselect, onchange, onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup
here's an example that bind's to all these events and shows what's going on http://jsfiddle.net/pxfunc/zJ7Lf/
I think you can filter out which events are truly relevent to your situation and detect what the text value was before and after the event to determine a change
The change event only fires after the input loses focus (and was changed).
There is no real solution to this - even in the links to other questions given above. In the end I have decided to use setTimeout
and call a method that checks every second! Not an ideal solution, but a solution that works and code I am calling is simple enough to not have an effect on performance by being called all the time.
function InitPageControls() {
CheckIfChanged();
}
function CheckIfChanged() {
// do logic
setTimeout(function () {
CheckIfChanged();
}, 1000);
}
Hope this helps someone in the future as it seems there is no surefire way of acheiving this using event handlers...