Detecting changes in input text box using jquery / javascript

in html and javascript, I can use keyup, focus, blur to detect most of the content changes in the text input, however, if the user makes a copy and pastes into the text input, how do I commit this change? The problem here is that the input is already in focus when the user inserts into it.

+5
source share
3 answers

You can capture the insert event ( http://www.quirksmode.org/dom/events/cutcopypaste.html )

$("#myinput").bind("paste",function(){
    //code here
})
+4
source
$("#myinput").change(function(){
    // whatever you need to be done on change of the input field
});

// Trigger change if the user type or paste the text in the field
$("#myinput").keyup(function(){
    $(this).change();
});

// if you're using a virtual keyboard, you can do :
$(".key").live('click',function(){
    $("#myinput").val($("#myinput").val()+$(this).val());
    $("#myinput").change(); // Trigger change when the value changes
});
+4
source

the text field has an OnChange event, which fires when a) the text field loses focus and the value in the text field has changed.

+3
source

All Articles