<HTML>
<HEAD>
<TITLE>
selection manipulation in a text field with IE4+
</TITLE>
<SCRIPT>
function getbrowser() {
var browser = navigator.appName
var version = navigator.appVersion
var version1 = version.substring(22,25)
var sisop = version.substring(26,37)
var versionn = version.substring(0,3)
var sisopn = version.substring(11,16)
if ( browser== "Microsoft Internet Explorer" )
{
alert("You are using the "+browser+", version "+version1+", with
"+sisop+"!");
return 1;//for IE
}
if ( browser=="Netscape" )
{
alert("You are using the "+browser+", version "+versionn+", with
"+sisopn+"!");
}
if ( browser!="Netscape" && browser!="Microsoft Internet Explorer")
{
alert("You are using the "+browser+", version "+version+", with
"+sisop+"!");
}
}
function replacetext(textInput)
{
if(getBrowser()==1)
{
if (document.selection)
{
var selectedRange = document.selection.createRange();
if (selectedRange.parentElement() == textInput)
{
var strSelection = document.selection.createRange().text ;
if (strSelection == "")
{
return false;
}
else
{
document.selection.createRange().text = "<B>" + strSelection +
"</B>"
return;
}
}
else
{
alert("You must select a text from within description to make it
bold");
}
}
else
{
alert("You must select a text to make it bold");
}
}
else
{
alert("Sorry for once Microsoft is Better.You can only Do this in
IE4+");
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName">
<INPUT TYPE="button" VALUE="show content" ONCLICK="replaceText(this);">
<BR>
<TEXTAREA NAME="textAreaName" ROWS="5" COLS="30">
Test For Getting Selection from a Textarea
</TEXTAREA>
<BR>
</FORM>
</BODY>
</HTML>
Kig på den..
Med venlig hilsen
/Jokke Jensen
www.jj-multimediedesign.dk