SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast BurakUeda's Avatar
    Join Date
    Apr 2005
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to select a part of the text?

    For example:
    HTML Code:
    <html>
    <body>
    <textarea name="textarea" id="textarea" cols="45" rows="5">This is some sample text to test.</textarea><br /><br />
    
    <input type="button" value="Select" />
    </body>
    </html>
    When "Select" button clicked, I want a part of the text selected, like from 3rd char to 10th char.

    How can I do this? (for firefox)

    Thanks.
    H u m o
    Uncensored Forums for Intelligent People

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    textarea.selectionStart = start;
    textarea.selectionEnd = end;
    or
    textarea.setSelectionRange(start, end);

    There is a good example at http://fudforum.org/forum/index.php?...869&#msg_34869 that first finds where the selection (if any) is, and then inserts some text around it and finally reselects the text after the insertion. That last part is what you are looking for: It starts with the line "if (textarea.setSelectionRange)"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •