How do I get the caret position in a textarea?

T

torch

I have trawled the internet for a solution to this one . All I need is the
caret position as a number. I have seen quite a few text insertion functions
that do something like this :

textarea.caretPos = document.selection.createRange().duplicate()

and then operate on the caretPos object - but all these solutions seem to
work by creating a selected area in the text and then replacing it - I just
want the caret position as a number.

Anyone got any clues?

Thanks
 
T

Thomas 'PointedEars' Lahn

torch said:
I have trawled the internet for a solution to this one . All I need is the
caret position as a number. I have seen quite a few text insertion functions
that do something like this :

textarea.caretPos = document.selection.createRange().duplicate()

and then operate on the caretPos object - but all these solutions seem to
work by creating a selected area in the text and then replacing it - I just
want the caret position as a number.

Anyone got any clues?

In the IE DOM, TextRange objects have a boundingLeft property.
Reads to me as it was what you are looking for:
<http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/duplicate.asp>

In the Gecko DOM, HTMLTextAreaElement objects have a selectionStart
property:
<http://www.xulplanet.com/references/objref/HTMLTextAreaElement.html>


HTH

PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top