Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use "input propertychange" events to capture just copy and paste by mouse

I want to capture change happened in textarea (keyup, and also copy&past), for keyup option i use :

$("textarea").keyup(function(){
   // ajax call here
});

i added this to capture pasting or cutting by mouse then trigger keyup event on the textarea:

$("textarea").on('input propertychange', function() {
    $(this).trigger(keyup);
});

the problem here is if i press a key in my keyboard , i get 2 ajax calls because the second function capture also keyup event.

Is there a way to prevent $("textarea").on('input propertychange'... from detecting a press key ?

like image 606
medBouzid Avatar asked Nov 16 '13 22:11

medBouzid


2 Answers

Why not test this simplification? As I tested your code, without success on detecting keyup in 'input propertychange' event.

You ignore keyup event:

//$("textarea").keyup(function(){
//// ajax call here
//});

And capture only this (do ajax call with this):

$("textarea").on('input propertychange', function() {
  //$(this).trigger(keyup);
  // do ajax call here
});

the latter ignores only some control keys, ie, key without corresponding character input.

like image 76
jacouh Avatar answered Nov 18 '22 15:11

jacouh


after doing some research i found a solution here :

How to run a function once when binding to multiple events that all trigger in Javascript?

i think this is the best solution to prevent calling event twice in my situation

like image 2
medBouzid Avatar answered Nov 18 '22 16:11

medBouzid