Skip to content Skip to sidebar Skip to footer

Textarea Selection Index

I have a textarea control in my website. I want to retrieve start and end position of selected text in the text area, for Internet Explorer. How can I do it?

Solution 1:

Might I encourage you to use Rangy?

A cross-browser JavaScript range and selection library. It provides a simple standards-based API for performing common DOM Range and Selection tasks in all major browsers, abstracting away the wildly different implementations of this functionality between Internet Explorer and DOM-compliant browsers.

See Selection Objects in Rangy.

Solution 2:

txtarea.selectionStart

and

txtarea.selectionEnd

are the indices of the selection.

This StackOverflow question shows you how to use them.

To read more on selected text, see this Introduction to Range. Specifically, you will have to use Microsoft Text Range for Internet Explorer.

Post a Comment for "Textarea Selection Index"