Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-03-2009
Member
 
Join Date: Feb 2009
Posts: 54
To copy-paste using Javascript.

hello friends,

I wanna know how can I perform copy-paste operations using javascript.
Does anyone have the script for this ? ........ kindly post

thanks a lot...
Reply With Quote
  #2  
Old 26-03-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: To copy-paste using Javascript.

Sometimes, when the user submits a form you may want to offer him the possibility to copy the content of a field (such as a textarea) to the clipboard so that if something goes wrong he doesn't lose what he just wrote.
Here is the JavaScript code to COPY :

Code:
<script type="text/javascript">
function CopyToClipboard()
{
   CopiedTxt = document.selection.createRange();
   CopiedTxt.execCommand("Copy");
}
</script>
In HTML you need to make this work like this:

Code:
<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>
Reply With Quote
  #3  
Old 26-03-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: To copy-paste using Javascript.

To COPY-PASTE:
Here's the JavaScript you need to use for implementing both a copy button and a paste button:

Code:
<script type="text/javascript">
function CopyToClipboard()
{
   CopiedTxt = document.selection.createRange();
   CopiedTxt.execCommand("Copy");
}
function PasteFromClipboard()
{  
   document.Form1.txtArea.focus();
   PastedText = document.Form1.txtArea.createTextRange();
   PastedText.execCommand("Paste");
} 
</script>
In HTML, you need to make this work like this -

Code:
<form name="Form1">
Select this text, copy it using the copy button, and paste it below.<br /><br />
<textarea id="txtArea" cols="60" rows="5"></textarea>
<br />
<input type="button" onClick="CopyToClipboard()" value="Copy to clipboard" />
<input type="button" onClick="PasteFromClipboard()" value="Paste from clipboard" /> 
</form>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "To copy-paste using Javascript."
Thread Thread Starter Forum Replies Last Post
I cannot do Copy and Paste or Paste Special between Excel Workbooks Acca-OR Windows Software 5 26-04-2012 04:16 AM
copy& paste in facebook ramada90 Technology & Internet 2 24-07-2011 10:59 PM
Copy and paste a conditional Halina Software Development 5 16-04-2009 11:59 PM
Copy Text from One Cell to Another in Microsoft Excel without copy & paste Computer_Freak Tips & Tweaks 0 18-03-2009 10:00 PM
Copy and Paste does not work M.Scarlet Microsoft Project 1 06-02-2008 03:46 PM


All times are GMT +5.5. The time now is 02:26 AM.