<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Finding selection start and end position in a textarea, in Internet Explorer</title>
	<atom:link href="http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/feed/" rel="self" type="application/rss+xml" />
	<link>http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/</link>
	<description>Random developer notes</description>
	<lastBuildDate>Wed, 03 Aug 2011 09:35:01 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: Jerry B.</title>
		<link>http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/comment-page-1/#comment-1607</link>
		<dc:creator>Jerry B.</dc:creator>
		<pubDate>Thu, 14 Jul 2011 17:46:55 +0000</pubDate>
		<guid isPermaLink="false">http://the-stickman.com/uncategorized/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/#comment-1607</guid>
		<description>I revised my solution to handle the issue noted by Simon Sanderson.

It moves a bookmark from the document.selection textrange to an element textrange. It correctly calculates the start and end positions regardless of where the element is in the page. It now handles end of field bookmarks with no selection.

function getSelectionRange(oElm)
{
	var $r	= { text: &quot;&quot;, start: 0, end: 0, length: 0 };
	if (oElm.setSelectionRange)
	{	/* W3C/Gecko/IE9+ */
		$r.start= oElm.selectionStart;
		$r.end	= oElm.selectionEnd;
		$r.text	= ($r.start !== $r.end) ? oElm.value.substring($r.start, $r.end): &quot;&quot;;
	}
	else if (document.selection)
	{	/* IE8- */
		var $oS, $oR, $oT;
		if (oElm.tagName &amp;&amp; oElm.tagName === &quot;TEXTAREA&quot;)
		{
			$oS	= document.selection.createRange().duplicate();
			$oR	= oElm.createTextRange();
			$oR.collapse(false);
			$oR.moveToBookmark($oS.getBookmark());
			if ($oS.text === &quot;&quot;)
			{
				$oT	= $oR.duplicate();
				$oT.moveEnd(&quot;character&quot;, 1);
				if ($oS.boundingWidth === $oT.boundingWidth &amp;&amp; $oS.boundingHeight === $oT.boundingHeight)
				{
					$oR	= $oT;
				}
			}
		}
		else
		{
			$oR	= document.selection.createRange().duplicate();
		}
		$r.text		= $oR.text;
		$r.start	= Math.abs($oR.moveStart(&quot;character&quot;, -1000000));
			$r.end		= $r.text.length + $r.start;
	}
	else if (document.getSelection)
	{	/* Netscape 4 */
		$r.text	= document.getSelection();
		$r.end	= $r.text.length;
	}
	$r.length	= $r.text.length;
	return $r;
}</description>
		<content:encoded><![CDATA[<p>I revised my solution to handle the issue noted by Simon Sanderson.</p>
<p>It moves a bookmark from the document.selection textrange to an element textrange. It correctly calculates the start and end positions regardless of where the element is in the page. It now handles end of field bookmarks with no selection.</p>
<p>function getSelectionRange(oElm)<br />
{<br />
	var $r	= { text: &#8220;&#8221;, start: 0, end: 0, length: 0 };<br />
	if (oElm.setSelectionRange)<br />
	{	/* W3C/Gecko/IE9+ */<br />
		$r.start= oElm.selectionStart;<br />
		$r.end	= oElm.selectionEnd;<br />
		$r.text	= ($r.start !== $r.end) ? oElm.value.substring($r.start, $r.end): &#8220;&#8221;;<br />
	}<br />
	else if (document.selection)<br />
	{	/* IE8- */<br />
		var $oS, $oR, $oT;<br />
		if (oElm.tagName &amp;&amp; oElm.tagName === &#8220;TEXTAREA&#8221;)<br />
		{<br />
			$oS	= document.selection.createRange().duplicate();<br />
			$oR	= oElm.createTextRange();<br />
			$oR.collapse(false);<br />
			$oR.moveToBookmark($oS.getBookmark());<br />
			if ($oS.text === &#8220;&#8221;)<br />
			{<br />
				$oT	= $oR.duplicate();<br />
				$oT.moveEnd(&#8220;character&#8221;, 1);<br />
				if ($oS.boundingWidth === $oT.boundingWidth &amp;&amp; $oS.boundingHeight === $oT.boundingHeight)<br />
				{<br />
					$oR	= $oT;<br />
				}<br />
			}<br />
		}<br />
		else<br />
		{<br />
			$oR	= document.selection.createRange().duplicate();<br />
		}<br />
		$r.text		= $oR.text;<br />
		$r.start	= Math.abs($oR.moveStart(&#8220;character&#8221;, -1000000));<br />
			$r.end		= $r.text.length + $r.start;<br />
	}<br />
	else if (document.getSelection)<br />
	{	/* Netscape 4 */<br />
		$r.text	= document.getSelection();<br />
		$r.end	= $r.text.length;<br />
	}<br />
	$r.length	= $r.text.length;<br />
	return $r;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: plr</title>
		<link>http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/comment-page-1/#comment-1483</link>
		<dc:creator>plr</dc:creator>
		<pubDate>Tue, 19 Oct 2010 02:27:41 +0000</pubDate>
		<guid isPermaLink="false">http://the-stickman.com/uncategorized/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/#comment-1483</guid>
		<description>Hi, what if i want to modify a SPECIFIC text in the textarea, and not modify the whole text area value? Can this be done?</description>
		<content:encoded><![CDATA[<p>Hi, what if i want to modify a SPECIFIC text in the textarea, and not modify the whole text area value? Can this be done?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon Sanderson</title>
		<link>http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/comment-page-1/#comment-1413</link>
		<dc:creator>Simon Sanderson</dc:creator>
		<pubDate>Wed, 09 Jun 2010 05:20:27 +0000</pubDate>
		<guid isPermaLink="false">http://the-stickman.com/uncategorized/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/#comment-1413</guid>
		<description>Hi Jerry - Your solution is perfect ... almost.  Unfortunatley I cannot see why it doesn&#039;t work in this one case.

For IE6: if I have a textarea such as

ABC

and I call your function for every move of the cursor I get the following debug trace in my software:

Selection mode mode (1 char at a time)
Start(0), End(1), Length(1), Text(A)
Start(1), End(2), Length(1), Text(B)
Start(2), End(3), Length(1), Text(C)

Non selection mode (simply pressing right arrow)
Start(0), End(0), Length(0), Text()
Start(1), End(1), Length(0), Text()
Start(2), End(2), Length(0), Text()
Start(1), End(1), Length(0), Text()

as you can possible see from the last line when I the cursor is to the right of the &#039;C&#039; I would expect the output to read
Start(3), End(3), Length(0), Text()

This is what happens in Firefox (albeit through a different branch of the function)

Any ideas how to modify the code to correct this small inconsistency?</description>
		<content:encoded><![CDATA[<p>Hi Jerry &#8211; Your solution is perfect &#8230; almost.  Unfortunatley I cannot see why it doesn&#8217;t work in this one case.</p>
<p>For IE6: if I have a textarea such as</p>
<p>ABC</p>
<p>and I call your function for every move of the cursor I get the following debug trace in my software:</p>
<p>Selection mode mode (1 char at a time)<br />
Start(0), End(1), Length(1), Text(A)<br />
Start(1), End(2), Length(1), Text(B)<br />
Start(2), End(3), Length(1), Text(C)</p>
<p>Non selection mode (simply pressing right arrow)<br />
Start(0), End(0), Length(0), Text()<br />
Start(1), End(1), Length(0), Text()<br />
Start(2), End(2), Length(0), Text()<br />
Start(1), End(1), Length(0), Text()</p>
<p>as you can possible see from the last line when I the cursor is to the right of the &#8216;C&#8217; I would expect the output to read<br />
Start(3), End(3), Length(0), Text()</p>
<p>This is what happens in Firefox (albeit through a different branch of the function)</p>
<p>Any ideas how to modify the code to correct this small inconsistency?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chandu</title>
		<link>http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/comment-page-1/#comment-1412</link>
		<dc:creator>Chandu</dc:creator>
		<pubDate>Tue, 08 Jun 2010 12:54:14 +0000</pubDate>
		<guid isPermaLink="false">http://the-stickman.com/uncategorized/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/#comment-1412</guid>
		<description>Hi,


document.selection.createRange(); not working for textbox. is there any alternative for it?




Regards,
Chandu</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>document.selection.createRange(); not working for textbox. is there any alternative for it?</p>
<p>Regards,<br />
Chandu</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen Andrew Carter</title>
		<link>http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/comment-page-1/#comment-1408</link>
		<dc:creator>Stephen Andrew Carter</dc:creator>
		<pubDate>Thu, 03 Jun 2010 13:58:36 +0000</pubDate>
		<guid isPermaLink="false">http://the-stickman.com/uncategorized/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/#comment-1408</guid>
		<description>function get_selection(the_id)
{
    var e = document.getElementById(the_id);
    
    //Mozilla and DOM 3.0
    if(&#039;selectionStart&#039; in e)
    {
        var l = e.selectionEnd - e.selectionStart;
        return { start: e.selectionStart, end: e.selectionEnd, length: l, text: e.value.substr(e.selectionStart, l) };
    }
    //IE
    else if(document.selection)
    {
        e.focus();
        var r = document.selection.createRange();
        var tr = e.createTextRange();
        var tr2 = tr.duplicate();
        tr2.moveToBookmark(r.getBookmark());
        tr.setEndPoint(&#039;EndToStart&#039;,tr2);
        if (r == null &#124;&#124; tr == null) return { start: e.value.length, end: e.value.length, length: 0, text: &#039;&#039; };
        var text_part = r.text.replace(/[\r\n]/g,&#039;.&#039;); //for some reason IE doesn&#039;t always count the \n and \r in the length
        var text_whole = e.value.replace(/[\r\n]/g,&#039;.&#039;);
        var the_start = text_whole.indexOf(text_part,tr.text.length);
        return { start: the_start, end: the_start + text_part.length, length: text_part.length, text: r.text };
    }
    //Browser not supported
    else return { start: e.value.length, end: e.value.length, length: 0, text: &#039;&#039; };
}

function replace_selection(the_id,replace_str)
{
    var e = document.getElementById(the_id);
    selection = get_selection(the_id);
    var start_pos = selection.start;
    var end_pos = start_pos + replace_str.length;
    e.value = e.value.substr(0, start_pos) + replace_str + e.value.substr(selection.end, e.value.length);
    set_selection(the_id,start_pos,end_pos);
    return {start: start_pos, end: end_pos, length: replace_str.length, text: replace_str};
}

function set_selection(the_id,start_pos,end_pos)
{
    var e = document.getElementById(the_id);
    
    //Mozilla and DOM 3.0
    if(&#039;selectionStart&#039; in e)
    {
        e.focus();
        e.selectionStart = start_pos;
        e.selectionEnd = end_pos;
    }
    //IE
    else if(document.selection)
    {
        e.focus();
        var tr = e.createTextRange();
        
        //Fix IE from counting the newline characters as two seperate characters
        var stop_it = start_pos;
        for (i=0; i &lt; stop_it; i++) if( e.value[i].search(/[\r\n]/) != -1 ) start_pos = start_pos - .5;
        stop_it = end_pos;
        for (i=0; i &lt; stop_it; i++) if( e.value[i].search(/[\r\n]/) != -1 ) end_pos = end_pos - .5;
        
        tr.moveEnd(&#039;textedit&#039;,-1);
        tr.moveStart(&#039;character&#039;,start_pos);
        tr.moveEnd(&#039;character&#039;,end_pos - start_pos);
        tr.select();
    }
    return get_selection(the_id);
}

function wrap_selection(the_id, left_str, right_str, sel_offset, sel_length)
{
    var the_sel_text = get_selection(the_id).text;
    var selection =  replace_selection(the_id, left_str + the_sel_text + right_str );
    if(sel_offset !== undefined &amp;&amp; sel_length !== undefined) selection = set_selection(the_id, selection.start +  sel_offset, selection.start +  sel_offset + sel_length);
    else if(the_sel_text == &#039;&#039;) selection = set_selection(the_id, selection.start + left_str.length, selection.start + left_str.length);
    return selection;
}

//Your welcome :)</description>
		<content:encoded><![CDATA[<p>function get_selection(the_id)<br />
{<br />
    var e = document.getElementById(the_id);</p>
<p>    //Mozilla and DOM 3.0<br />
    if(&#8216;selectionStart&#8217; in e)<br />
    {<br />
        var l = e.selectionEnd &#8211; e.selectionStart;<br />
        return { start: e.selectionStart, end: e.selectionEnd, length: l, text: e.value.substr(e.selectionStart, l) };<br />
    }<br />
    //IE<br />
    else if(document.selection)<br />
    {<br />
        e.focus();<br />
        var r = document.selection.createRange();<br />
        var tr = e.createTextRange();<br />
        var tr2 = tr.duplicate();<br />
        tr2.moveToBookmark(r.getBookmark());<br />
        tr.setEndPoint(&#8216;EndToStart&#8217;,tr2);<br />
        if (r == null || tr == null) return { start: e.value.length, end: e.value.length, length: 0, text: &#8221; };<br />
        var text_part = r.text.replace(/[\r\n]/g,&#8217;.'); //for some reason IE doesn&#8217;t always count the \n and \r in the length<br />
        var text_whole = e.value.replace(/[\r\n]/g,&#8217;.');<br />
        var the_start = text_whole.indexOf(text_part,tr.text.length);<br />
        return { start: the_start, end: the_start + text_part.length, length: text_part.length, text: r.text };<br />
    }<br />
    //Browser not supported<br />
    else return { start: e.value.length, end: e.value.length, length: 0, text: &#8221; };<br />
}</p>
<p>function replace_selection(the_id,replace_str)<br />
{<br />
    var e = document.getElementById(the_id);<br />
    selection = get_selection(the_id);<br />
    var start_pos = selection.start;<br />
    var end_pos = start_pos + replace_str.length;<br />
    e.value = e.value.substr(0, start_pos) + replace_str + e.value.substr(selection.end, e.value.length);<br />
    set_selection(the_id,start_pos,end_pos);<br />
    return {start: start_pos, end: end_pos, length: replace_str.length, text: replace_str};<br />
}</p>
<p>function set_selection(the_id,start_pos,end_pos)<br />
{<br />
    var e = document.getElementById(the_id);</p>
<p>    //Mozilla and DOM 3.0<br />
    if(&#8216;selectionStart&#8217; in e)<br />
    {<br />
        e.focus();<br />
        e.selectionStart = start_pos;<br />
        e.selectionEnd = end_pos;<br />
    }<br />
    //IE<br />
    else if(document.selection)<br />
    {<br />
        e.focus();<br />
        var tr = e.createTextRange();</p>
<p>        //Fix IE from counting the newline characters as two seperate characters<br />
        var stop_it = start_pos;<br />
        for (i=0; i &lt; stop_it; i++) if( e.value[i].search(/[\r\n]/) != -1 ) start_pos = start_pos &#8211; .5;<br />
        stop_it = end_pos;<br />
        for (i=0; i &lt; stop_it; i++) if( e.value[i].search(/[\r\n]/) != -1 ) end_pos = end_pos &#8211; .5;</p>
<p>        tr.moveEnd(&#039;textedit&#039;,-1);<br />
        tr.moveStart(&#039;character&#039;,start_pos);<br />
        tr.moveEnd(&#039;character&#039;,end_pos &#8211; start_pos);<br />
        tr.select();<br />
    }<br />
    return get_selection(the_id);<br />
}</p>
<p>function wrap_selection(the_id, left_str, right_str, sel_offset, sel_length)<br />
{<br />
    var the_sel_text = get_selection(the_id).text;<br />
    var selection =  replace_selection(the_id, left_str + the_sel_text + right_str );<br />
    if(sel_offset !== undefined &amp;&amp; sel_length !== undefined) selection = set_selection(the_id, selection.start +  sel_offset, selection.start +  sel_offset + sel_length);<br />
    else if(the_sel_text == &#039;&#039;) selection = set_selection(the_id, selection.start + left_str.length, selection.start + left_str.length);<br />
    return selection;<br />
}</p>
<p>//Your welcome <img src='http://the-stickman.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anonymous</title>
		<link>http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/comment-page-1/#comment-1398</link>
		<dc:creator>anonymous</dc:creator>
		<pubDate>Tue, 25 May 2010 13:09:05 +0000</pubDate>
		<guid isPermaLink="false">http://the-stickman.com/uncategorized/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/#comment-1398</guid>
		<description>pretty helpfull...thanks a ton!!</description>
		<content:encoded><![CDATA[<p>pretty helpfull&#8230;thanks a ton!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jerry B.</title>
		<link>http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/comment-page-1/#comment-1392</link>
		<dc:creator>Jerry B.</dc:creator>
		<pubDate>Wed, 12 May 2010 16:37:52 +0000</pubDate>
		<guid isPermaLink="false">http://the-stickman.com/uncategorized/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/#comment-1392</guid>
		<description>Here is my solution, it moves a bookmark from the document.selection textrange to an element textrange. It correctly calculates the start and end positions regardless of where the element is in the page. 

function getSelectionRange(oElm)
{
	var $r	= { text: &quot;&quot;, start: 0, end: 0, length: 0 };
	if (oElm.setSelectionRange)
	{	// W3C/Gecko
		$r.start= oElm.selectionStart;
		$r.end	= oElm.selectionEnd;
		$r.text	= ($r.start != $r.end) ? oElm.value.substring($r.start, $r.end): &quot;&quot;;
	}
	else if (document.selection)
	{	// IE
		if (oElm.tagName &amp;&amp; oElm.tagName === &quot;TEXTAREA&quot;)
		{
			var $oS	= document.selection.createRange().duplicate();
			var $oR	= oElm.createTextRange();
			var $sB	= $oS.getBookmark();
			$oR.moveToBookmark($sB);
		}
		else
			var $oR	= document.selection.createRange().duplicate();
		$r.text	= $oR.text;
		for (; $oR.moveStart(&quot;character&quot;, -1) !== 0; $r.start++);
		$r.end	= $r.text.length + $r.start;
	}
	$r.length	= $r.text.length;
	return $r;
}</description>
		<content:encoded><![CDATA[<p>Here is my solution, it moves a bookmark from the document.selection textrange to an element textrange. It correctly calculates the start and end positions regardless of where the element is in the page. </p>
<p>function getSelectionRange(oElm)<br />
{<br />
	var $r	= { text: &#8220;&#8221;, start: 0, end: 0, length: 0 };<br />
	if (oElm.setSelectionRange)<br />
	{	// W3C/Gecko<br />
		$r.start= oElm.selectionStart;<br />
		$r.end	= oElm.selectionEnd;<br />
		$r.text	= ($r.start != $r.end) ? oElm.value.substring($r.start, $r.end): &#8220;&#8221;;<br />
	}<br />
	else if (document.selection)<br />
	{	// IE<br />
		if (oElm.tagName &amp;&amp; oElm.tagName === &#8220;TEXTAREA&#8221;)<br />
		{<br />
			var $oS	= document.selection.createRange().duplicate();<br />
			var $oR	= oElm.createTextRange();<br />
			var $sB	= $oS.getBookmark();<br />
			$oR.moveToBookmark($sB);<br />
		}<br />
		else<br />
			var $oR	= document.selection.createRange().duplicate();<br />
		$r.text	= $oR.text;<br />
		for (; $oR.moveStart(&#8220;character&#8221;, -1) !== 0; $r.start++);<br />
		$r.end	= $r.text.length + $r.start;<br />
	}<br />
	$r.length	= $r.text.length;<br />
	return $r;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nux</title>
		<link>http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/comment-page-1/#comment-1385</link>
		<dc:creator>Nux</dc:creator>
		<pubDate>Sat, 10 Apr 2010 17:00:38 +0000</pubDate>
		<guid isPermaLink="false">http://the-stickman.com/uncategorized/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/#comment-1385</guid>
		<description>Just a note as this is high in Google...

boundingLeft will NOT work at all in this situation - it gives a value in pixels not characters.

Stine version is also wrong as the text it self might contain &quot;01&quot;.

The original version seems to work almost perfectly, but I think setting the attributes is not a good idea as they won&#039;t be updated and some script might use them to detect compatibility.

I said &quot;almost perfectly&quot;, because to get a caret position you should run:
element.focus()</description>
		<content:encoded><![CDATA[<p>Just a note as this is high in Google&#8230;</p>
<p>boundingLeft will NOT work at all in this situation &#8211; it gives a value in pixels not characters.</p>
<p>Stine version is also wrong as the text it self might contain &#8220;01&#8243;.</p>
<p>The original version seems to work almost perfectly, but I think setting the attributes is not a good idea as they won&#8217;t be updated and some script might use them to detect compatibility.</p>
<p>I said &#8220;almost perfectly&#8221;, because to get a caret position you should run:<br />
element.focus()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: surendra</title>
		<link>http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/comment-page-1/#comment-1377</link>
		<dc:creator>surendra</dc:creator>
		<pubDate>Thu, 18 Mar 2010 07:17:41 +0000</pubDate>
		<guid isPermaLink="false">http://the-stickman.com/uncategorized/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/#comment-1377</guid>
		<description>But Those are not working in all browsers except IE</description>
		<content:encoded><![CDATA[<p>But Those are not working in all browsers except IE</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Apanatshka</title>
		<link>http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/comment-page-1/#comment-1355</link>
		<dc:creator>Apanatshka</dc:creator>
		<pubDate>Thu, 14 Jan 2010 22:13:46 +0000</pubDate>
		<guid isPermaLink="false">http://the-stickman.com/uncategorized/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/#comment-1355</guid>
		<description>Thanks a lot for the script Stickman! :D I&#039;ve adapted it a bit to automatically update the selectionStart and selectionEnd. It does depend on the jquery library, but it can be written so it doesn&#039;t depend on jquery. Anyway, adding this file with condition comments works for me.

/*This javascript depends upon the jquery-1.3.2.js library

The content of this script sets a Selectionevent on every textarea in the document to update their selectionStart and selectionEnd. This is an IE hack to be able to use the normal selectionStart and selectionEnd Mozilla Firefox already has. The actual script to get the selection in IE is not mine! A person I only know as Stickman wrote it. This is the url: http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/
*/

$(document).ready(function(){
  $(&#039;textarea&#039;).select(function(){
    if(document.selection){
      var range = document.selection.createRange();
      var stored_range = range.duplicate();
      stored_range.moveToElementText(this);
      stored_range.setEndPoint(&#039;EndToEnd&#039;, range);
      this.selectionStart = stored_range.text.length - range.text.length;
      this.selectionEnd = this.selectionStart + range.text.length;
    };
  })
});</description>
		<content:encoded><![CDATA[<p>Thanks a lot for the script Stickman! <img src='http://the-stickman.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  I&#8217;ve adapted it a bit to automatically update the selectionStart and selectionEnd. It does depend on the jquery library, but it can be written so it doesn&#8217;t depend on jquery. Anyway, adding this file with condition comments works for me.</p>
<p>/*This javascript depends upon the jquery-1.3.2.js library</p>
<p>The content of this script sets a Selectionevent on every textarea in the document to update their selectionStart and selectionEnd. This is an IE hack to be able to use the normal selectionStart and selectionEnd Mozilla Firefox already has. The actual script to get the selection in IE is not mine! A person I only know as Stickman wrote it. This is the url: <a href="http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/" rel="nofollow">http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/</a><br />
*/</p>
<p>$(document).ready(function(){<br />
  $(&#8216;textarea&#8217;).select(function(){<br />
    if(document.selection){<br />
      var range = document.selection.createRange();<br />
      var stored_range = range.duplicate();<br />
      stored_range.moveToElementText(this);<br />
      stored_range.setEndPoint(&#8216;EndToEnd&#8217;, range);<br />
      this.selectionStart = stored_range.text.length &#8211; range.text.length;<br />
      this.selectionEnd = this.selectionStart + range.text.length;<br />
    };<br />
  })<br />
});</p>
]]></content:encoded>
	</item>
</channel>
</rss>

