Set caret position

C

cc

Hi,
Is possible set and get the caret position of cursor in a text field ?

Thanks,
Carlo
 
M

Martin Honnen

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.
 
C

Csaba Gabor

Martin said:
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
 

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,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top