i'm creating a link sharing that on bind() events of a specific textarea ( where i paste links ) it does an $.post
ajax callback with a preview (in case of youtube or vimeo link).
Basically, i would remove link into textarea each times that link is detected and preview is gotten.
this is the function that does the callback :
$('#writer').bind('change keypress keyup keydown',function() {
var value_= $('#writer').val();
$('#thumb-temp').hide();
$.post( 'checklink.php?', { string : value_ },
function(response) {
$('.writer').prepend(response);
$('#thumb-temp').show();
}).fail(function() { alert( "error" ) })
});
and the page checklink.php that should remove the link
<?
$link = $_POST['string'];
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
preg_match($reg_exUrl, $link, $url);
$link = $url[0];
?>
<script>clearTextarea('<? echo $link ?>')</script>
and in the end the clearTextarea() function
function clearTextarea(url) {
var _textarea = $('#writer');
var _curVal = _textarea.val();
var _curUrl = url;
var _regex = new RegExp( _curUrl , 'g' );
var _newVal = _curVal.replace( _regex , '' );
_textarea.val( _newVal );
}
Now, apparentely, this should works but nothing happens, any ideas ? I do not understand where I'm wrong :(