Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<HTML>
<HEAD><TITLE>Selection</TITLE>
<SCRIPT type="text/javascript">
function disp()
{
  var text = document.getElementById("text");
  var t = text.value.substr(text.selectionStart,text.selectionEnd-text.selectionStart);
  alert(t+"\nSelectionStart:"+text.selectionStart);

}
</SCRIPT>
</HEAD>
<BODY>

<TEXTAREA id="text">Hello, How are You?</TEXTAREA><BR>
<INPUT type="button"  value="Select text and click here"  onclick="disp();"/>
</BODY>
</HTML>
Posted
Comments
bbirajdar 4-Aug-12 13:53pm    
'Act' ? Your code does not seems to be a born actor/actress :)
ali_heidari_ 4-Aug-12 21:33pm    
wich scope dont run? the function?

Hi,
JavaScript
text.value.substr(text.selectionStart,text.selectionEnd-text.selectionStart);

Check your second parameter of substr. It should be integer.
Try this:
JavaScript
text.value.substr(text.selectionStart,10);




--Amit
 
Share this answer
 
Dear Friend,

C#
function disp()
{
    var text = document.getElementById("text").value;
    //  var t = text.substr(text.selectionStart,text.selectionEnd-text.selectionStart)
    var t = text.substr(text.selectionStart,10);
    alert(t+"\nSelectionStart:"+text.selectionStart);
}


<INPUT type="button" id="text" name="text" value="Select text and click here" onclick="disp()"/>

Hope this will fulfill your requirement.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900