Answer the question
In order to leave comments, you need to log in
How to track changes in the text of an input field?
The "change" event fires only after the focus is moved from the changed input.
And I want to immediately, as soon as the user climbed something to change.
$("input").on("edit", function() { <br>
/* добавить в заголовок формы предупреждение "не сохранено" */<br>
/* заблокировать закрытие окошка по ESC */<br>
});<br>
Answer the question
In order to leave comments, you need to log in
There is a wonderful jQuery Text Change
plugin www.zurb.com/playground/jquery-text-change-custom-event
I understand that a lot of time has passed, but for the future
$(document).on("input",function(ev){
console.log($(ev.target).val());
});
input event. It reacts right away:
https://learn.javascript.ru/events-change
onfocus - save the length of the text in the field
onkeyUp - check the length of the text in the field, and if it is not equal, then the text has been changed.
I recently had to write something like this for some browser:
setInterval(function(){
var curVal = $(".someInputs").val();
var prevVal = $(".someInputs").data("prevVal") || null;
if (prevVal !== curVal) {
// value changed
}
}, 100)
I would not forget about pasting text from the clipboard with the mouse.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question