Return selected text in textarea/text box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shravster
    New Member
    • Jun 2008
    • 2

    Return selected text in textarea/text box

    Hi,

    I was just wondering if there is a way to return the highlighted text in a text box or a text area.

    For instance:
    <textarea id="foo"> The quick brown fox jumped ... </textarea>
    <input type=text id="foo" value="The quick brown fox jumped ... ">

    Lets say I highlight the text 'brown fox' in one of those fields, is there a way for me to get that text and say, for instance, copy to clipboard without using the mouse menu etc..

    I get the copy to the clipboard part and tried document.getSel ection() in mozilla
    doesnt, and it doesnt seem to work for form fields. I'd be very thankful to anyone who has a solution to this.

    Thanks in advance.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    See this link for starters. Oh, and you can't have two elements with the same ID.

    Comment

    • shravster
      New Member
      • Jun 2008
      • 2

      #3
      Great that is just what I needed! :)

      Originally posted by acoder
      Oh, and you can't have two elements with the same ID.
      Right, it was more like textarea or text box, anyway thanks for pointing it out.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Oh, I see, nvm.

        Anyway, glad to see the link helped. If you have more questions, post again.

        PS. I noticed that you've just joined, so here's a "welcome to Bytes!" Hope you enjoy your stay ;)

        Comment

        Working...