tags:

views:

55

answers:

4

I have a textbox. On a button click, I want to copy all the contents of the textbox. Is that possible?

UpDate: I want to copy to the clipboard

A: 
<input type="text" id="source">
<input type="button" id="copy" value="Copy">

with:

$(function() {
  $("#copy").click(function() {
    var val = $("#source").val();
    // or
    var copy = $("#source").clone();
  });
});
cletus
A: 

yes, it is possible to do this using

.clone(true) // passing true will copy all of the event handlers too

To copy to the clipboard, the most reliable cross browser way requires using Flash. Take a look at ZeroClipboard (download here)

Russ Cam
A: 

Javascript can not paste to the clipboard. You have to use flash for that.

August Lilleaas
A: 

The best way to do this cross browser is using a flash plugin, for example the system found here± http://www.biglickmedia.com/misc/scripts/copy-paste.php

Note that this still doesn't work in all browsers (i.e. Chrome)

Pim Jager