how to replace selected text in html textarea?
mardagz
to [b]mardagz[\b]
here's my code but won't work..
function getSelectedText(){
if(window.getSelection){
return window.getSelection().toString();
}
else if(document.getSelection){
return document.getSelection();
}
else if(document.selection){
return document.selection.createRange().text;
}}
function bbrep(start, end){
$("#pPost").val($("#pPost").val().replace(getSelectedText(), start + getSelectedText() + end))};
key
$("#bbbold").click(function(){
bbrep("[b]", "[/b]");
return false;
})
anyone has an idea for this? :)