Set caret position

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cc

    #1

    Set caret position

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

    Thanks,
    Carlo


  • Martin Honnen

    #2
    Re: Set caret position



    cc wrote:
    [color=blue]
    > Is possible set and get the caret position of cursor in a text field ?[/color]

    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/

    Comment

    • cc

      #3
      Re: Set caret position

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

      Thanks,
      but how can get caret position?

      Carlo


      Comment

      • Martin Honnen

        #4
        Re: Set caret position



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

        For Mozilla you can read out
        textControl.sel ectionStart
        textControl.sel ectionEnd
        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/

        Comment

        • Csaba Gabor

          #5
          Re: Set caret position

          Martin Honnen wrote:[color=blue]
          > cc wrote:
          >[color=green][color=darkred]
          >>> In some browsers you can do that, see
          >>> <http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130>[/color][/color]
          >[color=green]
          >> but how can get caret position?[/color]
          >
          > For Mozilla you can read out
          > textControl.sel ectionStart
          > textControl.sel ectionEnd
          > 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.[/color]

          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

          Comment

          Working...