Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Auto copy to clipboard help

    Hey guys, I have a small script that i made, pretty much just reads a database and the script automatically creates a list of links compared to the amount of rows in the database, thats all fine, BUT, is there anyway for me to make it so that once the link is clicked, it automatically copies to the clipboard what is in a specific column of that specific row?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    No. PHP is server side and carries no abilities to copy anything to a client clip board. I don't think it even has hooks for the server clipboard now that I think of it.
    Assuming you mean your own clip board, this will be using javascript.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,441
    Thanks
    62
    Thanked 537 Times in 524 Posts
    Just to add to Fous reply, I think Flash can also access the users clipboard.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by tangoforce View Post
    Just to add to Fous reply, I think Flash can also access the users clipboard.
    Yep, your right it should be.
    To be more broad, you'll need a client side language, not a server side language to do this (although both Java and C# can do this as well, but I don't consider either as Server Side languages).

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Most client side languages will not have access to the clipboard either - for example JavaScript doesn't. JScript running in Internet Explorer can access the clipboard via an ActiveX control but only if that particular ActiveX is enabled.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    New Coder
    Join Date
    Sep 2009
    Posts
    54
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks guys, but still not quite sure where i should look...this is my code so far which does work perfectly fine for displaying a list of all the things that I would need but I need it so that when I click on the link which is in the last column, it pretty much copies the salescode into my clipboard

    PHP Code:
    <?php

    // load the configuration file.

    include("page-configurator.php");

            
    //load all news from the database and then OREDER them by newsid

            //you will notice that newlly added news will appeare first.

            //also you can OREDER by (dtime) instaed of (news id)

            
    $result mysql_query("SELECT * FROM salescode ORDER BY sitecode ASC",$connect);

            
    //lets make a loop and get all news from the database

            
    while($myrow mysql_fetch_assoc($result))

                 {
    //begin of loop

                   //now print the results:

                   
    echo "<tr><td width=\"25%\" valign=\"top\" bgcolor=\"615B67\" class=\"news\" style=\"border-bottom:1px dashed #A49FA5;border-left:1px solid #A49FA5;padding-top:.5em;padding-left:.5em;padding-bottom:.5em;\" align=center><table align=center width=\"100%\"><tr><td align=left><font size=\"2px\" color=\"ffcc00\"><b>";

                   echo 
    $myrow['sitecode'];
                   
                   echo 
    "</b></font></td></tr></table></td><td align=\"center\" width=\"50%\" valign=\"top\" bgcolor=\"615B67\" class=\"events\" style=\"border-bottom:1px dashed #A49FA5;\"><table align=center width=\"100%\"><tr><td width=\"50%\" class=\"events\" align=center><u>";
       
                   echo 
    $myrow['salescode'];

                   echo 
    "</u></td><td width=\"50%\" class=\"events\" align=left>";
                   
                   echo 
    $myrow['dealername'];
                   
                   echo 
    "</td></tr></table>";
                                  
                   echo 
    "</td><td align=\"right\" width=\"25%\" valign=\"middle\" bgcolor=\"615B67\" style=\"border-right:1px solid #A49FA5;border-bottom:1px dashed #A49FA5;\"><a target=\"_blank\" href=\"https://testing.com/loadSiteInfo.do?branch=123&siteCode=$myrow[sitecode]\"><font size=\"2px\"><b>";

                   echo 
    $myrow['sitecode'];

                   echo 
    "</b></font></a>&nbsp;&nbsp;</td></tr>";
                   
                 }
    //end of loop

    ?>

  • #7
    Regular Coder
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post
    I prefer making the user do the actual copy. Populate a hidden field with your PHP data, then using javascript you could call a function to display your text in an input box for the user to copy.

    Code:
    function copyText (sText) {
      window.prompt ("Clipboard: Ctrl+C, Enter", sText);
    }

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,441
    Thanks
    62
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by elite-fusion View Post
    but I need it so that when I click on the link which is in the last column, it pretty much copies the salescode into my clipboard
    As we've explained, there is no way in PHP that you can do this.

    You need to look at CLIENT SIDE languages / tech such as javascript or flash.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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