You are here: irt.org | FAQ | JavaScript | Text | Q356 [ previous next ]
Only in Netscape Navigator 4:
<P>Netscape and Netscape Navigator are registered trademarks of Netscape Communications Corporation in the United States and other countries. Netscape's logos and Netscape product and service names are also trademarks of Netscape Communications Corporation, which may be registered in other countries. Other product and brand names are trademarks of their respective owners. <SCRIPT LANGUAGE="JavaScript1.2"><!-- if (document.layers) { document.write('<FORM NAME="myform">'); document.write('<TEXTAREA NAME="mytext" ROWS="10" COLS="30" WRAP="VIRTUAL"><\/TEXTAREA>'); document.write('<P><INPUT TYPE="BUTTON" VALUE="Copy" onClick="document.myform.mytext.value = document.getSelection()">'); document.write('<\/FORM>'); } //--></SCRIPT>
The following was submitted by Galvin Doyle
In Internet Explorer 4+ you can do the following (which has much more power beyond this demonstration):
<script language="JavaScript"><!-- function getext() { var t = document.selection.createRange(); var vt = t.text; alert(vt); document.form.text.value = vt; } //--></script> <!--Then in the body of your page--> <form name="form" method="post" action=""> <textarea name="text"></textarea> <INPUT TYPE="BUTTON" VALUE="Select Text" onClick="getext()"> </form> <P>Some text to play with</p>