• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1579
  • Last Modified:

Copy Text from input to clipboard

Hi,

I need a simple script which when you click a button the text in the input is copied to clipboard.

The input:

<input name=link size=10 value="">

Can someone provide the full code for this?

Cheers

Andy.



0
AndrewShanklin
Asked:
AndrewShanklin
1 Solution
 
archrajanCommented:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<script language="javascript" type="text/javascript">

function copy_clip(txt)
{
 if (window.clipboardData)
   {
 
   window.clipboardData.setData("Text", txt);
   
  }
  }
</script>
<input type = "text" value = "expertsexchange" id = "txt">
<input type = "button" value = "copy" onclick = "copy_clip(document.getElementById('txt').value)" >
</BODY>
</HTML>
0
 
AndrewShanklinAuthor Commented:
Hi archrajan,

Thanks for providing the full source code :-)

Unfortunatley this works great in IE but not in Firefox - any ideas who to make it work in both?

If you could provide the soruce again that would be great.

Many thanks

Andy.
0
 
StobbyCommented:
I remember trying to do this a while back and found that firefox blocks this as standard. You can only get round it by using a 'signed script', which each user would then have to install.

Regards,

Stobby
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now