View Full Version : [Help needed] Copy & Paste

08-05-2011, 11:25 PM
Hi guys,

I'm pretty much a newbie when it comes to javascript and i'm still getting to grips with it all but i am in some need of some help.

I'm doing a relatively simple project for a friend of mine and what he is wanting is a simple web page with several buttons that have different information on them.

As you click each button it will automatically copy and then paste into a text area with each bit of information on a new line. I think I have grasped the copy and paste but I am a bit unsure as to how I copy each button and automatically paste into the text area.

once the relevant information is pasted into the textbox - he then wants a button to copy all of that information which can be pasted into a different system.

Here is my code that I have at the moment

<script type="text/javascript">

function copy()


Copytext = document.getElementById("button").value;



function paste()



PasteText = document.form.textarea.createTextRange();





<form name="form">

<input type="button" onClick="copy()" value="Option 1" />
<input type="button" onClick="copy()" value="Option 2" />
<input type="button" onClick="copy()" value="Option 3" />
<input type="button" onClick="copy()" value="Option 4" />
<input type="button" onClick="copy()" value="Option 5" />
<input type="button" onClick="copy()" value="Option 6" />


<textarea id="textarea" cols="60" rows="5"></textarea>
<br />
<input type="button" onClick="copy()" value="Copy text to clipboard" />

Any help would be appreciated

08-06-2011, 03:54 PM
There are lots of problems with copy/paste in different browsers for various security reasons. One bit of code may work in IE, but not other browsers. One piece of code might work in FF, but not IE, Chrome, etc.

The best solution is to use zeroclipboard:

I use it myself, and it is clean, cross-browser and easy to install/use.

08-06-2011, 11:59 PM
Hi JShor,

Thanks for the advice but its not what im looking for. The wbe browser he will be using is IE anyway and ive managed to work it out using the following code

<script language="JavaScript">
function clipboard()
var copy = document.getElementById('copy').createTextRange();


function paste()
var paste = document.selection.createRange();

<TEXTAREA ID="text" style="height:100px; width:250px;">
<BUTTON id="copy"onClick="clipboard(); paste();">Option 1</BUTTON>

cheers anyway!