textarea selection

admin

Administrator
Staff member
Hello.

I am developing a page that allows users to select text within a textarea, click on a button that will add formatting tags (such as "italic"), and place the tags around the selected text within the textarea( <i>SELECTED TEXT</i>). That part is up and working.

A problem arises if a user selects a word or phrase that appears in the textarea more than once, such as "and." The tags will always get placed around the first occurance of "and," not where that actual selection was.

A mouseUp event copies the selected text to a variable. Then I use string.indexOf() to find the location of the selected text within the textarea, which produces the problem if there are multiple occurances of the selected text.

Is there a better way for me to know where the actual selection is within the textarea, or a workaround for this? Here is a sample page:
<!-- m --><a class="postlink" href="http://www.cpe1.com/jstest/test.html">http://www.cpe1.com/jstest/test.html</a><!-- m -->

Thanks

(This only works on PCs )
 
Back
Top