This is because you are changing the html inside the text field, which is the default value. It seems that as soon as you set a new value (by entering or deleting something from the text field), this default value is ignored.
To get around this, you need to set the value of the text field, and not add it to the content:
function addUrl(e) { patt="http[s]*:\/\/"; if(e.match(patt)) u=e; else u="http://"+e; var newVal = $("textarea[name=\"content\"]").val() + "\n\r[url]"+u+"[/url]\n\r" $("textarea[name=\"content\"]").val(newVal); }
http://jsfiddle.net/infernalbadger/FpSsc/1/
Or, as Felix recommended:
function addUrl(e) { patt="http[s]*:\/\/"; if(e.match(patt)) u=e; else u="http://"+e; $("textarea[name=\"content\"]").val(function(i, v) { return v + "\n\r[url]"+u+"[/url]\n\r"; }); }
Richard Dalton
source share