Grab Selected Text

[Total: 0    Average: 0/5]

This example shows how to have text that is selected by the user be “found” by javascript.

Body Code:

Other text on document<BR>
<form name=exf1>
<textarea name="t1" rows=2 cols=20 >Some default text</textarea>
<BR><input type=button onclick="gettext()" value="Show selected text!">
function gettext(){ 
var sel = document.selection; 
if (sel!=null) { 
    var rng = sel.createRange(); 
    if (rng!=null) 
      alert (rng.text); 

Times Viewed: 2

Leave a Reply

Your email address will not be published. Required fields are marked *