By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,629 Members | 1,716 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,629 IT Pros & Developers. It's quick & easy.

Set caret position

P: n/a
cc
Hi,
Is possible set and get the caret position of cursor in a text field ?

Thanks,
Carlo
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a


cc wrote:
Is possible set and get the caret position of cursor in a text field ?


In some browsers you can do that, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

P: n/a
cc
> In some browsers you can do that, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130>


Thanks,
but how can get caret position?

Carlo
Jul 23 '05 #3

P: n/a


cc wrote:
In some browsers you can do that, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130>
but how can get caret position?


For Mozilla you can read out
textControl.selectionStart
textControl.selectionEnd
as number offsets, if both are the same then you have the caret position
as a number. If they are not the same I am not sure what you would
regard as the caret position, probably selectionStart.
IE doesn't expose the caret position as a number, you can insert stuff
at the caret position with the methods described.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4

P: n/a
Martin Honnen wrote:
cc wrote:
In some browsers you can do that, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130>

but how can get caret position?


For Mozilla you can read out
textControl.selectionStart
textControl.selectionEnd
as number offsets, if both are the same then you have the caret position
as a number. If they are not the same I am not sure what you would
regard as the caret position, probably selectionStart.


In some apps that's true (e.g. Consider Excel where you can select
(possibly non contiguous) ranges and then cycle through the cells of
this range with the tab key), but near as I can tell, the notion of caret
position (also in Word or OE) is either not well defined here (ie has no
meaning when characters are selected) or means the entire selected area.

In particular, note that the caret does not blink when you have characters
selected. Also, if you have characters selected and use the right arrow
key, the currently selected range will "collapse" and you will wind up
to the right of that formerly selected range. Similarly, pressing the
left arrow key will collapse the range and put the caret to the left (at
least in IE 6, FF 1.0.1+). I haven't been able to think up any experiment
(eg. cut, paste, etc.) which would reveal a differentiation between a left
or right internal caret position.

My testing has been minimal though, and I am happy to be corrected on this point.

Csaba Gabor from Vienna
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.