By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,623 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,623 IT Pros & Developers. It's quick & easy.

Can JS detect SELECTED text in a textArea

P: n/a
STB
Hi,

Can you pick out just the text that a user has selected in a TextArea using
JS?
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a


STB wrote:

Can you pick out just the text that a user has selected in a TextArea using
JS?


It depends on whether the browser offers an API, some like Netscape
7.1/7.2, Mozilla 1.4 or later, Firefox do with
textControl.value.substring(textControl.selectionS tart,
textControl.selectionEnd)
and IE/Win also does
document.selection.createRange().text
others like Opera don't offer an API.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

P: n/a
Martin Honnen <ma*******@yahoo.de> wrote in message news:<41**********************@newsread4.arcor-online.net>...
STB wrote:

Can you pick out just the text that a user has selected in a TextArea using
JS?


It depends on whether the browser offers an API, some like Netscape
7.1/7.2, Mozilla 1.4 or later, Firefox do with
textControl.value.substring(textControl.selectionS tart,
textControl.selectionEnd)
and IE/Win also does
document.selection.createRange().text
others like Opera don't offer an API.


Don't imitate this, because it is bad code, but in IE you can do
something like this:

function wrapSelectionBold (element) {
var range = document.selection.createRange();
if (range.parentElement() == element) range.text = '<b>' +
range.text + '<\/b>';
}

<input type="button" value="bold"
onclick="wrapSelectionBold(this.form.inputId)" />
Jul 23 '05 #3

P: n/a
"STB" <ne*******@nodomain.co.uk> wrote in message news:<cj*******************@news.demon.co.uk>...
Hi,

Can you pick out just the text that a user has selected in a TextArea using
JS?


We were recently discussing the issue here:

http://groups.google.com/groups?hl=e...%3D10%26sa%3DN
Jul 23 '05 #4

P: n/a
On 29 Sep 2004 20:10:17 -0700, lawrence wrote:
"STB" <ne*******@nodomain.co.uk> wrote in message news:<cj*******************@news.demon.co.uk>... ...
Can you pick out just the text that a user has selected in a TextArea using
JS?

.... http://groups.google.com/groups?hl=e...%3D10%26sa%3DN


1st message also available through this shorter link..
<http://google.com/gr**************************************@posting.g oogle.com>

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Jul 23 '05 #5

P: n/a
lawrence wrote:
"STB" <ne*******@nodomain.co.uk> wrote in message
news:<cj*******************@news.demon.co.uk>...


Please do not post attribution novels.
Can you pick out just the text that a user has selected in a TextArea
using JS?


We were recently discussing the issue here:

http://groups.google.com/groups?hl=e...%3D10%26sa%3DN

1. The thread you point to does not answer the OP's question.
However, other threads do:

<http://groups.google.com/groups?as_q=textarea+%22selected+text%22&as_ugroup =comp.lang.javascript&scoring=d&filter=0>

2. Mozilla Firefox and Venkman don't work well together, since Venkman was
designed for debugging with Mozilla Seamonkey; one should use that UA
instead.
PointedEars
--
I was in a car crash, it wasn't the war, but I'll never be quite the same...
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.