Hi,

I've had this code that works half the time in IE (and the other half I tip-toed around it to make it work) to find the selectionStart and selectionEnd of a textarea.

Here it is:

Code:
function bounds()
{

	info = document.getElementById("post");
	msg = info.value;

	if(document.selection)
	{
		if(!sel)
		{
			sel = document.selection.createRange();
		}

		var temp = sel.text.length;

		while(info.value.indexOf(sel.text) > 0)
		{
			sel.moveStart("character", -1);
		}

		start = parseInt(sel.text.length - temp);
		end = parseInt(sel.text.length);

		if(start == 0 && end == 0)
		{
			info.focus();
			sel = document.selection.createRange();
		}
	}
	else
	{
		start = info.selectionStart;
		end = info.selectionEnd;
	}

}
I just pasted the whole function in there, so you can see what mozilla can do in 2 lines (is this understandable with any other browsers... safari, opera, etc? I haven't actually tested on those) takes IE quite a bit more to do.

So what happens is when there is actually some text selected, this method works fine. But when, instead, nothing is selected, the range behaves instead like an insertion point, so I can do something like sel = "stuff to insert"; and insert text where the cursor is in the textarea. This has been okay so far, but now I am trying to implement something where I actually need to know what the value of the point is (ie. what I would get in mozilla if I just found out what the selectionStart value is). Does anybody have any suggestions of a way to modify the code or maybe just scrap it altogether to do this? Been trying a few things but to no avail.

Thanks,
Douglas