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 detecting a change as there are obviously other ways of entering text into an input.
6 Answers
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
5 Comments
paste and input events, I added those after finding them here, jquery - How to detect right mouse click + paste using JavaScript?...heres the updated fiddleinput seems to be the one-stop shop at least in IE9/FF/ChromeI have found that this works:
$(document).ready(function(){
$('textarea').bind('input propertychange', function() {
//do your update here
}
})
1 Comment
The change event only fires after the input loses focus (and was changed).
1 Comment
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...
Comments
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
6 Comments
change() the second textbox will handle it as written in answer.
.change()if it has changed.