Results 1 to 10 of 10

Thread: Copy & Paste

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    Copy & Paste

    Is there javascript code to copy text inside textarea until I can paste it in any place

  2. #2
    Hyperactive Member bsw2112's Avatar
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    292
    this might give you ideas

    Code:
    <html>
    <head>
    <style>
    
    #lay1 { position:absolute; top:-100px; left:-100px; visibility:hidden }
    </style>
    <script>
    
    function placeIt(frm1) {
    	
    	var obj;
    	obj=document.getElementById("lay1")
    	obj.style.visibility = "visible";
    	obj.style.left = frm1.x.value;
    	obj.style.top = frm1.y.value;
    	txt.innerText = frm.a.value
    }
    </script>
    
    </head>
    
    <body>
    <form name="frm">
    <textarea cols=20 rows=5 name = "a" ></textarea>
    <br>
    x coor <input type ="text" name = "x" size ="5"><br>
    y coor <input type ="text" name = "y" size ="5"><br><br>
    <input type = "button" onClick="placeIt(this.form)" value = "place">
    </form>
    <div id ="lay1"><p id = "txt"></p></div>
    </body>
    
    </html>
    i tested this only in IE6
    of course coords must me numberic only
    i didn't validate anything

    bsw2112

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    I do not mean that

    I mean copy text to paste it in any other programs .. for example to paste it in NotePad program.

  4. #4
    Hyperactive Member bsw2112's Avatar
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    292
    i don't think it is possible
    because you don't have the ability in javascript
    to write to files

    maybe windows script host (WSH) can do that but i am not sure..

    you can do what you want using a server side language like perl or asp. those languages can access files

    bsw2112

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    Copy

    I mean copy to memory not to files in server.

  6. #6
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    he wants a function to highlight and copy text to the clip board through javascript.
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

  7. #7
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    I don't remember there being an official (clipbook is OS specific) or portable (you can do this with IE) way of doing it with javascript, but I believe you might want to try Java.

    You can at least highlight a textarea using its DOM "select()" method.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    Yes

    Yes or With Java or VBScript or PHP or ...........

  9. #9
    New Member
    Join Date
    Aug 2002
    Location
    lebanon
    Posts
    13
    insert this code into the <head> section of your HTML code...
    and have a nice day...
    ...best regards...!!
    ____________________________________________________

    <script>

    //Copytext to clipboard- by Gennero ([email protected])
    //Submited to DynamicDrive.com
    //Visit http://www.dynamicdrive.com for this script

    bBool=false
    var copiedtext=""
    var tempstore=""

    function initiatecopy() {
    bBool=true;
    }

    function copyit() {
    if (bBool) {
    tempstore=copiedtext
    document.execCommand("Copy")
    copiedtext=window.clipboardData.getData("Text");
    if (tempstore!=copiedtext) {
    alert(copiedtext);
    }
    bBool=false;
    }
    }

    document.onselectionchange = initiatecopy
    document.onmouseup = copyit

    </script>
    ____________________________________________________
    Any Problem made by man is solved by man.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    Thanks M.R Abou_ghazi

    Thank you too much . Relly very nice code.

Posting Permissions

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



Click Here to Expand Forum to Full Width