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
    Jul 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question validation for highlited text

    I am building simulation. User has to highlite text and copy it. So the copy command would be available only after user highlites text. Is it possible to validate text field for highliting? Another word how could I check if all text in a field is highlited?

    Thank you for any ideas.
    Last edited by chelentano; 06-12-2003 at 04:47 PM.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You can check to see the lenght of the text range selected and the length of the text in the element it was selected from.

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not a bad idea, A1ien51, thank you. Actually this solution would work for me, I just have to modify it:

    <body>

    Other text on document<BR>
    <form name=exf1>
    <textarea name="t1" rows=2 cols=20 >Some default text</textarea>
    <BR><input type=button onclick="gettext()" value="Show selected text!">
    </form>
    <script>
    function gettext(){
    var sel = document.selection;
    if (sel!=null) {
    var rng = sel.createRange();
    if (rng!=null)
    alert (rng.text);
    }
    }
    </script>


  •  

    Posting Permissions

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