Home     My Faqts     Contributors     About     Help    

faqts : Computers : Programming : Languages : JavaScript : Forms : TextAreas/TextFields

FAQTs repaired & updated!
Thanks for your patience...
Entry Add Entry Alert - Edit this Entry

Did You Find This Entry Useful?

5 of 7 people (71%) answered Yes
Recently 5 of 7 people (71%) answered Yes

How do I get only part of the text area by selecting it with the mouse?

Dec 26th, 2001 20:32

Duvoor Kirthi, s h
only in IE4+


below is the code which will work inn IE4.irt will not work in NN4 but
might wrok in NN6
<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 
      {
         alert(strSelection);
      }
   }
   else
   {
      alert("You must select a text from within textarea");
   }
}
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="Get Text"  ONCLICK="replaceText(this);">
<BR>
<TEXTAREA NAME="textAreaName" ROWS="5" COLS="30">
Test For Getting Selection from a Textarea
</TEXTAREA>
<BR>
</FORM>
</BODY>
</HTML>



© 1999-2004 Synop Pty Ltd