SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get Selected Text From a TextArea

    Hi.

    Im completely new to JS, so Im probly missing something simple.
    What Im trying to do, is get the length of the selected text in a textarea. I have it working in WinIE6 / Opera9 / Netscape8 / Aol / Msn / Avant1 / Crazy2 / Mozilla1.5, but, macs are a problem. In Safari1.0 / Mac IE5 I got nothing. I need another else if with a safari compatable version of this in, but I dont know what to use? Ive tried everything I can think of


    function checkSelected(theform, tag) {
    if (document.selection && document.selection.createRange().text.length > 0) {
    alert('IE');
    } else if ( (theform.message.selectionEnd - theform.message.selectionStart) > 0) {
    alert('Moz');
    } else {
    alert('oh damn.');
    }
    }
    Last edited by Purity; Aug 20, 2006 at 15:13. Reason: adding a more descriptive title.


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
  •