Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detecting change in a text input box using jquery/javascript

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

like image 308
user121196 Avatar asked Jul 02 '09 02:07

user121196


People also ask

How to detect change in input text jQuery?

The change() is an inbuilt method in jQuery that is used to detect the change in value of input fields. This method works only on the “<input>, <textarea> and <select>” elements.

How to check if textbox value is changed in jQuery?

Answer: Use the input Event You can bind the input event to an input text box using on() method to detect any change in it.

How to detect change in input text JavaScript?

Use any or all of them onchange event, onpropertychange event, onkeyup event, onpaste event and oninput event in the input element and call a function to see the effect. click outside of it to see.


3 Answers

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

$("#myinput").bind("paste",function(){
    //code here
})
like image 113
jeroen.verhoest Avatar answered Sep 28 '22 07:09

jeroen.verhoest


$("#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
});
like image 35
Alex Avatar answered Sep 28 '22 07:09

Alex


the textbox has an OnChange event that fires when a) the text box loses focus AND the value within the text box has changed.

like image 35
Stephen Wrighton Avatar answered Sep 28 '22 06:09

Stephen Wrighton