#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    54
    Rep Power
    12

    highlighted text javascript


    I have a form with a textarea element where a user can enter text. I want the user to be able to highlight some text that they entered in the textarea and I want to write JavaScript functions that then manipulate only the highlighted text.

    Is it possible using JavaScript to determine what text inside a textarea has been highlighted and save that text as a variable?

    Thanks for any help you can offer.
  2. #2
  3. No Profile Picture
    CF sMod
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Maine, USA (a.k.a. Boonies)
    Posts
    242
    Rep Power
    15
    If "textarea" is a reference to the textarea:

    var str = textarea.value.substring(textarea.selectionStart, textarea.selectionStop);

    Gecko-only.

IMN logo majestic logo threadwatch logo seochat tools logo