I want to check whether the URL has been input into textarea or not. This is a function that checks textarea:
$('#text textarea').on('input paste', function() {
checkUrl($(this));
});
Only one URL is allowed, so after finding the URL handler is unbind using off:
function checkUrl(elem) {
var words = elem.val().split(/\s+/);
$.each(words, function(index, element) {
if (isValidURL($.trim(element))) {
$.ajax({...}); // Ajax call
elem.off('input paste');
return;
}
});
}
Function checkUrl is called not only once but twice after pasting the URL (CTRT+V). Ajax is also triggered twice.
Thanks a lot in advance.
EDIT
I've changed my code according to this:
$('#text textarea').bind('paste', function() {
var _this = $(this);
setTimeout( function() {
checkUrl(_this);
}, 100);
});
It's now working with paste handler only, but the main problem persists...