Results 1 to 9 of 9

Thread: select all for text in text box

  1. #1
    Join Date
    Feb 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default select all for text in text box

    I am looking for a script for select all to highlights text in text box, Just like the one in every code page in DD code pages, it is much better if it is auto saved to clipboard, ( acting like Cntrl +A, Cntrl +C )

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Something like this:

    http://www.dynamicdrive.com/dynamici...selectform.htm

    (Note: the "Copy to Clipboard" function only works in IE [as far as I am aware of].)

    Hope this helps.

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The method, actually methods - focus() and select(), for selecting text in a form element like a textarea or text input is rather simple. In most basic terms it is:

    Code:
    element.focus();
    element.select();
    where element represents the form element. Form elements can be 'gotten' in a variety of ways and the best way usually depends upon the markup and other things like - the rest of the script.

    Having the text data that you select transferred to the clipboard is a bit more complicated. There is an IE only method and I think there is a way that works in some other browsers or at least a way to make a sort of virtual clipboard.

    Accessing the user's clipboard is impolite as, it potentially and in most cases will wipe out any text or image data already on the user's clipboard.

    How this is done in IE was gone into in detail here:

    http://codingforums.com/showthread.php?t=65106

    For other browsers, there is a link to info on that in that thread:

    http://www.ms-inc.net/ViewThread.aspx?ThreadID=169

    I'm not sure (as already mentioned) if it includes the ability to access the clipboard.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Feb 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Thanks

    Thanks, SORRY, I think I was looking on the wrong place in the the Website, That was just what I was looking for

  5. #5
    Join Date
    Feb 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    How to make it a button not a text ( the clickable text),

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Simply change this:

    Code:
    <a class="highlighttext" href="javascript:HighlightAll('test.select1')">Select All</a>
    to this:

    Code:
    <a class="highlighttext" href="javascript:HighlightAll('test.select1')"><img src="image.gif"></a>
    Hope this helps.

  7. #7
    Join Date
    Feb 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    actually I am looking for something like
    Code:
    <BUTTON type="button" OnClick="href="javascript:HighlightAll ('test2.select1'" style="width:70px;height:20px;z-index:2">
    not a gif
    also i tried your code it is giving me error
    TKS
    Last edited by mailtosaleh; 02-28-2007 at 06:51 AM.

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script type="text/javascript">
    
    /*
    Select and Copy form element script- By Dynamicdrive.com
    For full source, Terms of service, and 100s DTHML scripts
    Visit http://www.dynamicdrive.com
    */
    
    //specify whether contents should be auto copied to clipboard (memory)
    //Applies only to IE 4+
    //0=no, 1=yes
    var copytoclip=1
    
    function HighlightAll(theField) {
    var tempval=eval("document."+theField);
    tempval.focus();
    tempval.select();
    if (document.all&&copytoclip==1&&tempval.createTextRange){
    therange=tempval.createTextRange()
    if(therange.execCommand)
    therange.execCommand("Copy")
    else
    return;
    window.status="Contents highlighted and copied to clipboard!"
    setTimeout("window.status=''",1800)
    }
    }
    
    </script>
    
    </head>
    <body>
    <form action="#" name="test2">
    <input type="button" onclick="HighlightAll ('test2.select1')" style="width:70px;height:20px;z-index:2;" value="Select All"><br>
    <textarea name="select1" cols="50" rows="5" wrap="virtual">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce luctus turpis. Proin a lacus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed non purus in tellus semper porta. Praesent vel quam nec orci mollis dignissim. Nulla ultrices, tellus quis semper pretium, eros augue eleifend risus, at dictum massa urna blandit metus. Nullam libero metus, scelerisque in, sollicitudin in, tristique nec, tortor. Sed eu felis. Integer rutrum mauris id nisl. Praesent cursus. Vivamus faucibus.</textarea>
    </form>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Feb 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thats great, It looks much better, You are great

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
  •