Highlighting part of the text in a text box

A

Aria

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.
 
J

Janwillem Borleffs

Aria said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top