I have the solution and work in IE,Firefox and chrome
this funtion remplace a selected string in textbox
example:
x=hello (the selected text in textbox)
v1=<strong>
v2=</strong>
<input type="button" value="Bold" onclick="remplace('<strong>','</strong>')" /> (input button)
function remplace(v1,v2)
{
var elementRef = document.getElementById("IDofTextBox");
if (document.selection) {
str = document.selection.createRange().text
document.selection.createRange().text = v1 + str + v2;
}
else if ((elementRef.selectionStart) || (elementRef.selectionStart == '0'))
{
var startPos = elementRef.selectionStart;
var endPos = elementRef.selectionEnd;
var str = elementRef.value.substring(startPos, endPos);
elementRef.value = elementRef.value.substring(0, startPos) + v1 + str + v2 + elementRef.value.substring(endPos, elementRef.value.length);
}
else
{
elementRef.value += valueToInsert;
}
}
the result <strong>x</strong> inside of textBox
If you use master.page and add this code in a asp:Content you need this function to find the real Id of the control
function RealID(id)
{
var strId="";
var elm="";
for(i = 0; i < document.forms[0].elements.length; i++)
{
elm = document.forms[0].elements[i];
if (elm.id.indexOf(id)!=-1)
{
strId=elm.id;
return(strId);
}
}
}