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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Multiple text area to clipboard in IE

    Hi there folks. Amateur coder here looking for some help with a personal project. I have a form with multiple text area's, i am looking to take all the text area's and send it to the clipboard. I know i have to use javascript but cannot seem to get multiple text area's selected. Could anyone please help? I have been given the following and told it can be adapted to copy the actual form contents itself but no idea how.

    Code:
    <script type="text/javascript">
    function CopyToClipboard()
    {
       CopiedTxt = document.selection.createRange();
       CopiedTxt.execCommand("Copy");
    }
    </script>
    
    <form name="Form1">
    
    Here is some text you can copy. You can copy text from anywhere on the page, simply select it and press the Copy to clipboard button. Then you can paste it anywhere you want, in Notepad, Visual Studio or in the textarea below.
    
    <br /><br />
    
    <textarea id="txtArea" cols="60" rows="5">You can also copy text from this textarea. Or you can paste the text here, using the Ctrl+V key combination.</textarea>
    
    <br />
    
    <input type="button" onClick="CopyToClipboard()" value="Copy to clipboard" />
    
    </form>
    Can anyone help me copy the entire form possibly and not the text area's?

    Many thanks

    Chris McLauchlan
    Last edited by chrismcl09; 06-26-2009 at 08:43 PM. Reason: Change title as per rules.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Your script will work only in IE. And it will only work once, as the IE clipboard does not hold multiple clips. The only way to copy multiple form fields or text areas to the clipboard is to combine them all into a hidden field and then use a button to send the combined content to the clipboard.

    Code:
    <textarea id = "copytext1" rows = 5 cols = "20"></textarea>
    
    <textarea id = "copytext2" rows = 5 cols = "20"></textarea>
    
    <textarea id = "copytext3" rows = 5 cols = "20"></textarea>
    
    <textarea id="holdtext" style ="display:none;"></textarea>
    <br><br>
    <input type = "button" onClick="ClipBoard();" value = "Copy to Clipboard"</button> 
    
    <script type = "text/javascript">
    
    function ClipBoard() {
    holdtext.innerText = copytext1.innerText + " " + copytext2.innerText + " " + copytext3.innerText;
    Copied = holdtext.createTextRange();
    Copied.execCommand("RemoveFormat");
    Copied.execCommand("Copy");
    window.status="Contents copied to clipboard"
    setTimeout("window.status=''",2500)
    }
    
    </script>

    But once again, it will only work in IE.


    Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose.


    "Insanity is doing the same thing over and over again, but expecting different results." - Rita Mae Brown
    Last edited by Philip M; 06-26-2009 at 04:53 PM. Reason: Typo

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Philip,

    You do not know how releived i am that you come up with a solution. It works perfectly. And no form needed either. All can be manipulated with CSS/HTML. I have changed the topic name to suit as per the rules. My appologies about that. I did not read that first. Please do accept my appologies. I think i will be back to this forum when i need help in the future.

    Can i just ask quickly, this will work if i name a select query like this wont it?
    Code:
    <select Name="test">
            <option value="test">Test</option>
    </select>
    Chris
    Last edited by chrismcl09; 06-26-2009 at 08:50 PM. Reason: Add code brackets

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by chrismcl09 View Post
    Can i just ask quickly, this will work if i name a select query like this wont it?
    Code:
    <select Name="test">
            <option value="test">Test</option>
    </select>
    Well, why not try it and find out?

    "name" should be so spelled, lower case.

    If you are thinking of trying to capture a select box value in the copy-contents-of-form-to-clipboard, that will not work as it stands. Here is the way to do that:-


    Code:
    <select id = "sel">
    <option value = "None" selected>Select A Fruit><option>
    <option value = "Apple">Apple</option>
    <option value = "Orange">Orange</option>
    <option value = "Peach" >Peach</option>
    </select>
    
    <textarea id = "copytext1" rows = 5 cols = "20"></textarea>
    
    <textarea id = "copytext2" rows = 5 cols = "20"></textarea>
    
    <textarea id = "copytext3" rows = 5 cols = "20"></textarea>
    
    <textarea id="holdtext" style ="display:none;"></textarea>
    <br><br>
    <input type = "button" onClick="ClipBoard();" value = "Copy to Clipboard"</button> 
    
    <script type = "text/javascript">
    
    function ClipBoard() {
    var val = document.getElementById("sel").value;
    holdtext.innerText = copytext1.innerText + " " + copytext2.innerText + " " + copytext3.innerText + " Option Value " + val;
    Copied = holdtext.createTextRange();
    Copied.execCommand("RemoveFormat");
    Copied.execCommand("Copy");
    window.status="Contents copied to clipboard"
    setTimeout("window.status=''",2500)
    }
    
    </script>
    Last edited by Philip M; 06-27-2009 at 07:57 AM.


  •  

    Posting Permissions

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