Wednesday, March 11, 2009

Copy to clipboard in javascript

If you want to copy the text from any text component (html component), you can try this java script function, for this example I'm using a text field, just taylor it to fit your needs.

Java script function

function copy(text) {
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text);
  }
}


Calling the function

<--! 
input type="button" value="Copy To Clipboard" onclick="copy(document.your_form_name.your_textarea_name.value);
-->

Cheers!

No comments:

Post a Comment