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

20,526

Solution 1

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

Solution 2

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.

Share:
20,526
medBouzid
Author by

medBouzid

CEO at Scratchoo, a JS ninja, ex Ruby developer, currently writing functional code for BEAM, author of Webpack for beginners, I've been writing software since 2007, I love climbing and traveling :) You can follow me on Twitter

Updated on October 15, 2021

Comments

  • medBouzid
    medBouzid over 2 years

    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 ?

  • jiguang
    jiguang over 6 years
    I found that use 'input propertychange' in iOS11 and when I delete up to 5 characters, it will show some space between cursor and the last letter.