Set caret position

Discussion in 'Javascript' started by cc, Apr 4, 2005.

  1. cc

    cc Guest

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

    Thanks,
    Carlo
    cc, Apr 4, 2005
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Apr 4, 2005
    #2
    1. Advertising

  3. cc

    cc Guest

    > 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
    cc, Apr 4, 2005
    #3
  4. 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/
    Martin Honnen, Apr 4, 2005
    #4
  5. cc

    Csaba Gabor Guest

    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
    Csaba Gabor, Apr 4, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SHVnaA==?=

    Current Caret Position

    =?Utf-8?B?SHVnaA==?=, Feb 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    475
    Rob Meade
    Feb 5, 2004
  2. Camel
    Replies:
    3
    Views:
    6,318
    Camel
    Jul 12, 2005
  3. R. Kangas
    Replies:
    0
    Views:
    174
    R. Kangas
    Jan 26, 2006
  4. brendan
    Replies:
    0
    Views:
    186
    brendan
    Aug 29, 2006
  5. Ciaran
    Replies:
    9
    Views:
    483
    Ciaran
    Nov 25, 2009
Loading...

Share This Page