469,328 Members | 1,316 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

How do I get the caret position in a textarea?

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

Jul 23 '05 #1
4 5410
Ivo
"torch" <to***@torch.com> wrote in message
news:ca**********@newsg4.svr.pol.co.uk...
I have trawled the internet for a solution to this one . All I need is the
caret position as a number.


See this thread (url may wrap):
<URL:
http://groups.google.com/groups?thre...44a441750%40ne
ws.wanadoo.nl >

HTH
Ivo

Jul 23 '05 #2
On Sun, 13 Jun 2004 17:16:28 +0200, Ivo wrote:
http://groups.google.com/groups?thre...44a441750%40ne
ws.wanadoo.nl


Also, try this alternate..
<http://groups.google.com/groups?th=296d438401e265d5>

(shrugs) I have been practising the 'black art'
of shortening Google Usenet URL's recently and
have become quite good at it. ..Maybe I should
write a page on it.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #3
Ivo
"Andrew Thompson" wrote
Ivo wrote:
http://groups.google.com/groups?thre...44a441750%40ne ws.wanadoo.nl


Also, try this alternate..
<http://groups.google.com/groups?th=296d438401e265d5>

(shrugs) I have been practising the 'black art'
of shortening Google Usenet URL's recently and
have become quite good at it. ..Maybe I should
write a page on it.


Yes, please do. This is impressive.
Ivo
Jul 23 '05 #4
torch wrote:
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
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Zbigniew Braniecki | last post: by
7 posts views Thread by =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.