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 ?
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 ?
- Why not just use the second function?! – Tamer Shlash Commented Nov 16, 2013 at 22:24
- @TamerShlash because the second event doesn't work in all browsers – medBouzid Commented Nov 16, 2013 at 22:25
2 Answers
Reset to default 8Why 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.
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