Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selected text in Textarea

Status
Not open for further replies.

armandoxxx

Programmer
Nov 28, 2000
3
SI
is there a function or method or any way to get the value of selected text in text area ...

for example ..
I have "this is my text" in text area .. and I only select "this" in the textarea ...

is there any function that would return this selected on button click ??

10x

Armando
 
Try

Code:
function getSelected(form)
{
  text = (form) ? document.selection.createRange().text : document.getSelection();
  alert(text)
}
</SCRIPT>
</HEAD>

...

<FORM>
<INPUT TYPE=&quot;button&quot; VALUE=&quot;Selection?&quot; onClick=&quot;getSelected(this.form)&quot;>
<TEXTAREA NAME=&quot;myText&quot; COLS=40 ROWS=2&quot;>
Hello from me

</TEXTAREA>
</FORM>
Billy H

bhogar@acxiom.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top