Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Cursor Position (IE only)

Status
Not open for further replies.

jaredn

Programmer
Sep 1, 1999
1,506
US
Me and my friend (erik arvidsson) came up with this. Just make sure you remember that if you click a button or soemthing, the cursor position is lost, so you need to do it onkeydown or something like that :

function getCursorPosition(obj)
{
var selrange,r;

selRange = document.selection.createRange();
r = obj.createTextRange();

if (!r.inRange(selRange)) return -1;

r.setEndPoint("endToEnd", selRange);
r.moveStart("textEdit", -1);

return r.text.length;
} jared@eae.net -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top