selected text

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

    #1

    selected text

    Hello all

    Is it possible to get which text in a textarea element is selected ?

    If so How?

    Thanks Rob



  • Ivo

    #2
    Re: selected text

    "Rob" <reply_@news_gr oup.please> wrote[color=blue]
    > Is it possible to get which text in a textarea element is selected ?[/color]

    The function below returns any selected text (in IE, Netscape and iCab). Or
    if no text is selected, null is returned. You have to do additional tests to
    see if it is in the textarea. You should call this function onmousedown and
    not onclick, because that may unselect the selection.

    function isselect(){
    if((d=document) .getSelection)r eturn d.getSelection( );
    if(d.selection && d.selection.cre ateRange)return
    d.selection.cre ateRange().text ;
    return false;
    }

    HTH
    Ivo


    Comment

    • Douglas Crockford

      #3
      Re: selected text

      >>Is it possible to get which text in a textarea element is selected ?
      [color=blue]
      > The function below returns any selected text (in IE, Netscape and iCab). Or
      > if no text is selected, null is returned. You have to do additional tests to
      > see if it is in the textarea. You should call this function onmousedown and
      > not onclick, because that may unselect the selection.
      >
      > function isselect(){
      > if((d=document) .getSelection)r eturn d.getSelection( );
      > if(d.selection && d.selection.cre ateRange)return
      > d.selection.cre ateRange().text ;
      > return false;
      > }[/color]

      I would be happier with the function if it looked like this:

      function isselect() {
      var d = document;
      if (d.getSelection ) {
      return d.getSelection( );
      } else if (d.selection && d.selection.cre ateRange) {
      return d.selection.cre ateRange().text ;
      }
      return false;
      }

      Comment

      • Rob

        #4
        Re: selected text


        "Rob" <reply_@news_gr oup.please> schreef in bericht
        news:vPq2c.1733 $pN4.1267@amsne ws03.chello.com ...[color=blue]
        > Hello all
        >
        > Is it possible to get which text in a textarea element is selected ?
        >
        > If so How?
        >
        > Thanks Rob
        >
        >
        >[/color]

        thanks, just what I needed
        Rob


        Comment

        Working...