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

Highlighting part of the text in a text box

P: n/a
Hi all,

I've been struggling with this for days. How can I use javascript to
high light a part of the text in a textbox or a textarea?

OR

if the user highlights a part of the text in a textbox or a textarea,
how can I say which part of the text is highlighted? (ie: at what
character the highlight starts and at what character the highlight
ends).

thanks in advance.

Oct 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Aria wrote:
if the user highlights a part of the text in a textbox or a textarea,
how can I say which part of the text is highlighted? (ie: at what
character the highlight starts and at what character the highlight
ends).


function sel(o) {
if (o.selectionStart) {
return o.value.substring(o.selectionStart,o.selectionEnd) ;
} else {
return document.selection.createRange().duplicate().text;
}
}

....
<input type="text" onmouseup="alert(sel(this))" />
JW

Oct 12 '05 #2

P: n/a
thanks. Is o.selectionStart and o.selectionEnd the code to use for
netscape?

Oct 12 '05 #3

P: n/a
Aria wrote:
thanks. Is o.selectionStart and o.selectionEnd the code to use for
netscape?


Yes.
JW

Oct 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.