form.element.value from selected text

Discussion in 'Javascript' started by Martin Nadoll, Apr 9, 2009.

  1. hello

    is it possible, to have a <textarea> element in a form, to write text into
    that, select a part of that text and with a button to trigger a function
    <button... onClick="showSelected('parameter???')">
    that can work with the selection.

    For example:
    function showSelected(param???) {
    // maybe:
    my_Selected_Part_Of_Textarea=param???;
    // or:
    my_Selected_Part_Of_Textarea=document.forms['myForm'].elements['myTextarea'].selectedvalue;
    alert(my_Selected_Part_Of_Textarea);
    }

    Does javascript capture, what is selected in that <textarea> element?

    Thanks for any idea about that,
    Martin Nadoll
    Martin Nadoll, Apr 9, 2009
    #1
    1. Advertising

  2. Martin Nadoll wrote:

    > Does javascript capture, what is selected in that <textarea> element?


    With Mozilla and I think Opera and Safari too the browser exposes two
    properties named
    selectionStart
    selectionEnd
    on input type="text" and on textarea element objects. So you can access
    textarea.value.substring(textarea.selectionStart, textarea.selectionEnd)

    IE has a different API for the complete selection in the document,
    whether it is inside of a control or whether it is inside of normal
    elements like p or div. There you can use
    document.selection.createRange().text
    to get the selected text.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Apr 9, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rod  Snyder

    moving from form element to form element

    Rod Snyder, May 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    405
    Vidar Petursson
    May 29, 2004
  2. Iceman
    Replies:
    1
    Views:
    430
    Steve Pugh
    Jan 7, 2004
  3. HANM
    Replies:
    2
    Views:
    706
    Joseph Kesselman
    Jan 29, 2008
  4. datactrl
    Replies:
    2
    Views:
    82
    datactrl
    Jun 8, 2004
  5. OccasionalFlyer
    Replies:
    6
    Views:
    246
    Garrett Smith
    Jul 29, 2009
Loading...

Share This Page