SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot Tekdot's Avatar
    Join Date
    Jul 2005
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    copy textbox to clipboard

    Hello,

    First off, I'm a complete javascript newb. Heres my problem, Im trying to copy text box to the clipboard and heres what i have so far

    in the header
    Code:
    <SCRIPT LANGUAGE="JavaScript">
    
    function ClipBoard() 
    {
    alert("copied");
    window.clipboardData.setData("Text",document.links.txtbox1);
    }
    </SCRIPT>
    in the body
    Code:
    <form id=links>
    <input type="text"  id="txtbox1" class="formtext" onClick=\'highlight(this);\' style="width: 400px" size="70" value="dummy text" /><br />
    <BUTTON onClick="ClipBoard();">Copy</BUTTON>
    </form>
    Need a large site moved (5 GB +)? I can help, PM me for pricing.
    [PR 4] Large File Hosting Site looking for link trades

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lots of little things, see red type

    Code:
    <script type="text/javascript">
    
    function ClipBoard() 
    {
    alert("copied");
    window.clipboardData.setData("Text",document.links.txtbox1.value);
    }
    
    
    </script>
    
    
    
    <form name="links">
    <input type="text"  name="txtbox1" class="formtext" onclick="highlight(this)" style="width: 400px" size="70" value="dummy text" /><br />
    <BUTTON onclick="ClipBoard()">Copy</BUTTON>
    </form>

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,807
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Code:
    function ClipBoard() 
    {
    if (window.clipboardData) {
       alert("copied");
       window.clipboardData.setData("Text",document.links.txtbox1.value);
    }
    }
    That way the alert wont come up telling people it is copied when it isn't where the browser is not Internet Explorer (only IE allows the page to access the clipboard).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •