Copy Text from input to clipboard

Posted on 2006-06-02
Last Modified: 2012-06-27

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?



Question by:AndrewShanklin
    LVL 25

    Accepted Solution

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <TITLE> New Document </TITLE>
    <META NAME="Description" CONTENT="">

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

    function copy_clip(txt)
     if (window.clipboardData)
       window.clipboardData.setData("Text", txt);
    <input type = "text" value = "expertsexchange" id = "txt">
    <input type = "button" value = "copy" onclick = "copy_clip(document.getElementById('txt').value)" >

    Author Comment

    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

    LVL 4

    Expert Comment

    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.



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Mobile App Development with PhoneGap

    PhoneGap can help you leverage your already existing HTML5, JavaScript, and CSS skills in order to create and deploy cross-platform mobile apps.This program comprehensively covers HTML5 mobile app development from top to bottom.

    Suggested Solutions

    A common challenge, or question, when working with two calendar dates is: What is the difference between the specified days? As is frequently the case, the answer is: It depends... What kind of difference do you want? Given two date obje…
    In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now