Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2002
    Location
    germany
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to get the selected text

    hello,

    can anybody please tell me how to get the selected text in a document.

    when some text is selected I want to show the text in an alert box.

    hope it is posible,


    ANIL

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    This will get you halfway (from http://www.xs4all.nl/~ppk/js/selected.html)


    <html>
    <head>
    <script language="javascript">
    function getSel(){
    if (document.getSelection) txt = document.getSelection();
    else if (document.selection) txt = document.selection.createRange().text;
    else return;

    alert(txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," "));
    }

    </script>
    </head>
    <body>
    <form>
    lskdfas dflkjasdflkj hsdakjf hsadhf asd;lkjf s;lkdfj;lkas jfdlkasjd fkjsahfd kljahf p98wefh p9ewh0f27f hqwhfe audsnf oiwuhf 9hf 9dw8hf <br><br>
    lskdfas dflkjasdflkj hsdakjf hsadhf asd;lkjf s;lkdfj;lkas jfdlkasjd fkjsahfd kljahf p98wefh p9ewh0f27f hqwhfe audsnf oiwuhf 9hf 9dw8hf <br><br>
    lskdfas dflkjasdflkj hsdakjf hsadhf asd;lkjf s;lkdfj;lkas jfdlkasjd fkjsahfd kljahf p98wefh p9ewh0f27f hqwhfe audsnf oiwuhf 9hf 9dw8hf <br><br>
    <input type="button" onclick="getSel();" value="show text">
    </form>
    </body>
    </html>

  • #3
    New Coder
    Join Date
    Oct 2002
    Location
    germany
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks a lot friend that was really useful...


  •  

    Posting Permissions

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