How do I know the whole text of an INPUT element is selected

Discussion in 'Javascript' started by datactrl, Jun 7, 2004.

  1. datactrl

    datactrl Guest

    Hi, all

    How do I know the whole text of an INPUT element is selected?

    Jack
     
    datactrl, Jun 7, 2004
    #1
    1. Advertising

  2. datactrl

    Ivo Guest

    "datactrl" wrote
    > How do I know the whole text of an INPUT element is selected?
    >


    <script>
    function isselect(){
    if (document.getSelection)
    return document.getSelection(); // if NS
    if (document.selection && document.selection.createRange)
    return document.selection.createRange().text; // if IE4+
    return false;
    }
    function test(){
    var a=document.forms[0].elements['thetext'].value;
    var b=isselect();
    if(a==b) alert('Selected all!');
    else if(b) alert('Selected:\n'+b);
    else alert('Naught selected.');
    }
    </script>
    <form>
    <input type="text" name="thetext" value="select me">
    <input type="button" value="Click me" onmousedown="test()">
    </form>

    HTH
    Ivo
     
    Ivo, Jun 7, 2004
    #2
    1. Advertising

  3. datactrl

    datactrl Guest

    Thanks Ivo, it's a good help.

    Jack
     
    datactrl, Jun 8, 2004
    #3
    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. Hans Merkl
    Replies:
    1
    Views:
    476
    Steven Cheng[MSFT]
    Dec 12, 2005
  2. Stefan Mueller
    Replies:
    5
    Views:
    541
    Steven Saunderson
    Jul 10, 2006
  3. \A_Michigan_User\
    Replies:
    2
    Views:
    929
    \A_Michigan_User\
    Aug 21, 2006
  4. HANM
    Replies:
    2
    Views:
    753
    Joseph Kesselman
    Jan 29, 2008
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    262
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page