Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery keyup detect paste text from input

Tags:

I have to use here jquery keyup to detect if user enter any text or not, but my problem is if user use paste the text using mouse, it won't be able to detect it, can you tell me the reason?

here is my source code:

$("textarea").keyup(function(){         if($(this).val().length !== 0){             $('#submit').attr('disabled',false); 
like image 421
Ben Avatar asked Feb 08 '14 06:02

Ben


2 Answers

Apparently there are some situations where jQuery doesn't work for pasting. You might need to bind to several events as shown in following reference to catch users pasting contents accurately.

From Soliciting Fame - jQuery keyup vs bind - (from way-back machine)

// detect the change $('input#myId').bind("change keyup input",function() {      // handle events here }); 

UPDATE: bind was deprecated on Jquery 3.0 and was replaced with on

// detect the change $('input#myId').on("change keyup input",function() {      // handle events here }); 
like image 150
jwwishart Avatar answered Oct 11 '22 10:10

jwwishart


In this particular situation enough will be just bind to the input event:

$('textarea').bind("input", function() {}); 
like image 40
Ilia Rebane Avatar answered Oct 11 '22 12:10

Ilia Rebane