JavaScript - Auto Copy To Clipboard Help
Hey guys, I have a small page that reads from a mysql db and pretty much makes a row on the page for every row in the db, but, i need a way to have it so that when i click on a link from each row, it should automatically copy one of a cell from the db. so i have 3 columns in the DB: SITECODE, SALESCODE, and DEALERNAME, on my html page I have 4 colums, SITECODE, SALESCODE, DEALERNAME, and one that has a link which has a URL in it and adds the SITECODE automatically into it for each row.
I need it so that when i click on the link for each row, it automatically copies to the clipboard the SALESCODE for that row. This is what I have so far, but it does not work for some reason. Code: <script type="text/javascript"> function copy_to_clipboard(text) { if(window.clipboardData) { window.clipboardData.setData('$myrow[salescode]',text); } else { } return false; } </script>[/B] <?php // load the configuration file. include("page-config.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 onclick=\"copy_to_clipboard('text')\" target=\"_blank\" href=\"https://testing/loadSiteInfo.do?branch=usa&siteCode=$myrow[sitecode]\"><font size=\"2px\"><b>"; echo $myrow['sitecode']; echo "</b></font></a> </td></tr>"; }//end of loop ?> Similar TutorialsCode: solved ! Hi, i have several links which i am trying to add an on click command to which copies a certain code to the clip board so the user can paste the code with out having to manually copy it first. i have this Code: $latest = simplexml_load_file('codes_ending_soon.xml'); foreach ($latest->discount as $discount) { $code = $discount->id; $link = $discount->link; $store = $discount->storeName; $logo = $discount->logo; $details = $discount->details; if($code_count <=4) {?> <div class="code_cont"> <div class="code_logo"><img src="<?php echo $logo?>" alt="<?php echo $store." code"?>" title="<?php echo $store." code"?>" height="32" /></div> <a class="code" href="<?php echo $link?>" title="Click to see related product(s) / retailer and apply code" onclick="window.clipboardData.setData(<?php echo $code?>)"><?php echo $code?></a> <div class="description"><?php echo $details?></div> </div><?php $code_count++; } }?> but when i click on the link nothing seems to copy at least in firefox anyway? can anyone help me please thanks Luke Hi! Not sure if this is the right forum for this, but I'm using Javascript so it kinda made sense I have some Javascript that is selecting text from a form textarea and copying it to the clipboard: Code: document.myForm.myTextarea.focus(); document.myForm.myTextarea.select(); document.execCommand( 'Copy' ); This works great. However there is a problem when I try to paste the text somewhere else. Assuming that the text that is being copied is a URL ( ie. http://www.google.com ), I would like it to be pasted as a link. When I grab a URL from the address bar inside a web browser and paste it somewhere ( such as an e-mail ), it automatically shows up as a clickable link. When I put a URL into my form textarea and run the javascript, it gets pasted as a plain text ( ie. not underlined and not clickable ). Why are these two different? I've tried running a program to see what is actually copied into the clipboard and I don't see any differences. There must be something that denotes the URL copied from the address bar as a link and therefore makes it clickable when pasted. Is there a way to force this in order to make what is copied to the clipboard from my form textarea a clickable link? Thanks! Hello, I've been looking around the web for a simple JavaScript to solve this problem but can't seem to find something that would work both in IE and FF and the other major browsers? So basically I have a page listing about a dozen badges people can use to link back to me. I have presented the code for each badge (eg. a href, img src, alt...) in a separate textarea and I'd really love to add a link next to each textarea that would say something like "Click here to copy to Clipboard" then it would copy the text from within the corresponding textarea to the Clipboard so as to eliminate the need for Ctrl+A, Ctrl+C. Thank you in advance people! Hi, I have a code which i'm trying to make work. I need it so when I select the button it copies the code to the clipboard, then go directly to the site (eg: google.com), then I need the code to be pasted in to the browser bar and hit enter. I've been working on this for hours. I know i'm doing something wrong if someone could give me a simple code with these features then I could add in the stuff. This is the javascript that copies the code: Code: <script language="JavaScript"> var clip = null; function init() { clip = new ZeroClipboard.Client(); clip.setHandCursor( true ); clip.setText("*********CODE TO COPY IS HERE**********"); clip.glue('d_clip_button'); clip.addEventListener('complete', my_complete); setInterval(checkDone, 1000); } This is what I have to send them to the site. Code: <input type="button" value="Click Here" onClick="javascript:window.open('http://google.com');" > I don't know how to have it all in one so it copies the code then opens the site and pastes into the browser and enters. Regards, Andrew I have a small snippet of code which will copy the contents of a textbox to the clipboard when a small image, say a button, is clicked. I want to achieve a similar effect when I click a hotspot on an image, but in this case the text will have to come from...well, I don't know. Maybe the title in an area tag? This is what I have so far for a textbox: Code: //clipboard copy function ClipBoard(what){ Copied = document.getElementById(what).createTextRange(); Copied.execCommand("Copy"); alert ("Information copied to the clipboard. Use CTRL-V to paste."); } <textarea id="holdtext1"></textarea> <img border="0" src="copyclick.gif" onclick="ClipBoard('holdtext1');" alt=" Click to copy text to clipboard / CTRL-V to paste" style="cursor: hand" width="18" height="18"> Does anyone have any ideas? I have been to this forum many times as a lurker and I have picked up some good information. For this I give Thanks wholeheartedly. My situation: I enter information in a system based on the # of a report that comes in. So if I see a report that says "333" i want to enter specific information for "333" same with "444" and "555" and so on and so forth. So I want to have a drop down menu for 111, 222, 333, 444 etc... Basically what I need is, if I select the report # from the drop down menu, I want it to copy information from a HIDDEN textbox to the clipboard. That's it! I've been trying to figure it out, but to no avail. Sorry I am fake coder Hello. I have a textarea where user can select a text then copy to clipboard (using EditArea script for highlighting) I need append additional information to the selected text so it won't be visible in the textarea, but only appear after copied to clipboard. For example: Code: text line one text line two text line three user selected word "two", hit CTRL+C to copy into clipboard (or used browser's context menu), but in clipboard it should be saved as: "selected word 'two'" What would be the approach? Thank you. do anyone know how do make a form that automatic tab when we paste something into the box and sort it out automatically. Like cd-key box. when we copy n paste cd-key into the box it automatic inert everything into correct places. Thanks Hi I have some code but have no skills so need a lot of help here is what I have Code: <script type="text/javascript"><!-- alert(window.clipboardData.getData ('Text' )) {if (1,2,3,4) //repeats 4 times { //open 1.exe } else if (5,6,7,8) //repeats 4 times { // open 2.exe }else if (9,10,11,12) //repeats 4 times { // open 3.exe } else { // } //--></script> I need to get it to listn for sertan words and numbers and make a decision on what file to open the .exe files. It needs to recognise when the info has changed in the clipboard Please help <- thats me Hello, I don't know if this can be done in Javascript, or requires any other language but i was wondering if this would be possible. I would like to embed this Javascript code in to a PHP file and then for it to run automatically upon the PHP file loading: Code: <td class="smallDesc"> <a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script> </td> The Javascirpt is the Facebook Share button that basically allows users that have Facebook to share the page there currently on in their Facebook status by pressing the button, but if there not logged in it shows the login page, not a problem just continue the script. The current button i which is what i want to load automatically in the PHP file is located here, to test the functionalilty just click "Share" button in blue.. http://watch-movies-online.anyfilman...-Movie-17.html To summarise, i would like the above Javascript code to execute automatically upon pageload of this PHP file.. http://www.watch-movies-online.anyfi...p://google.com. If that could be done, and if this also is possible.. i would like for the "Share" button on the external page that is loaded from the Javascript code above to be clicked automatically so in effect when ever someone visits the PHP page after clicking "Click Here to Watch/Stream 2012 Online For Free" on this page it will automatically load the Facebook Share box, and automatically click the "Share" Button and then close the page if possible, but not required. Please feel free to ask any questions, i'll be happy to answer. Thanks in advance. Best Regards, Jonathan. Don't even know where to post this as I have never thought about it; I've just made my game have a image upload script in, and a album showing the users images. How could I make have a link saying "Copy Link" that if clicked will copy the picture url to clip board. I've seen places like w3schools use in but not as tuts though. Please this will really help, desplayin the link is ugly EDIT: I've found the following code but I don't understand how I turn it into a link or button. Code: <script> window.clipboardData.setData('text','This has been copied to your clipboard.'); </script> I have this line of code: <input type='text' id='fCode' style="width:875px; height:22px;"/><br /><br /> Does anyone know how to add a copy button to so when you click it it copies everything in the box to your clipboard? Thanks -Wardman Hello, I am needing help in copying a url to another href on a page. Here is the scenario: I have a page with multiple <LI>. Within each <LI> there is A hidden link An image A visible link This is the code within each <LI>: Code: <h2 class="postTitle" style="display: none;"><a href="URL to copy">LI Name</a></h2> <a href="Copied URL"><img alt="" src="LI Image" /></a> <a href="Copied URL">LI Name</a> Each <LI> will contain a different image, LI name, and link. I am needing a way to get the hidden URL for each LI copied into the visible href. Hope this makes sense. Thanks in advance for your help. I have this line of code: <input type='text' id='fCode' style="width:875px; height:22px;"/><br /><br /> Does anyone know how to add a copy button to so when you click it it copies everything in the box to your clipboard? Thanks -Wardman since there are troubles with innerHTML in IE ..... instead of : Code: target.innerHTML = src.innerHTML; --> Code: this.copy_innerHTML = function(src,target) { //remove all target inner elements while(target.hasChildNodes()){target.removeChild(target.childNodes[0])} for (var j = 0; j<src.childNodes.length-1; j++) { target.appendChild(src.childNodes[j].cloneNode(true)); } } a) Tested in FF and GC b) in IE this works, but stuff does not appear where it should. EDIT: if text nodes removed , then even in ff does not work, does not find textarea inside target node. That is, the error pops up, previously only notable at IE. HTML & CSS validation is OK. Any advice ? I have been looking all over google and i cant find it. How would you make a text box and when you type in it it would display the words underneath?
how can i copy the contents of the fields in this form so that i can just paste it anywhere? thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> function copy(other) { var tempval=eval("document."+other) tempval.focus() tempval.select() therange=tempval.createTextRange() therange.execCommand("Copy") } </script> </head> <body> <form id="other" name="other" method="post" action=""> <p>DSL Number: <input type="text" name="phonenumber" /> </p> <p>Full Name: <input type="text" name="fullname" /> </p> <p>Country: <input type="text" name="country"/> </p> <p> <textarea name="txtarea" id="txtarea" cols="45" rows="5"></textarea> </p> <p> <input type="button" value="Copy" onclick="copy();" /> </p> </form> </body> </html> I have a copy to clip board function in a page for short cut notes but currently it is enbeded with several copy to options ... hear is a part of the code ... [code] <html> <head> <title>Case Shortcut 1.0</title> </head> <SCRIPT language=JavaScript src="xxxxxxx"></SCRIPT> <BODY bgcolor=cccccc onload="loadPin('one')"> <table border="0" bordercolor="#000000" style="background-color:#FFFFCC" width="500" cellpadding="3" cellspacing="3"> <tr> <td> <SCRIPT LANGUAGE="JavaScript"> function ClipBoard1() { holdtext1.innerText = copytext1.innerText; Copied1 = holdtext1.createTextRange(); Copied1.execCommand("Copy"); } </SCRIPT> <SPAN ID="copytext1" STYLE="height:*;width:300;background-color:White"> xxxxxx. I called and left message with callback number and pin. Callback Number: bbbbbbbbbbb PIN <SCRIPT language=JavaScript src="http://doris/res/scripts/datePin.js"></SCRIPT> <SPAN id=datepinHolder></SPAN></SPAN> <TEXTAREA ID="holdtext1" STYLE="display:none;"> </TEXTAREA> <BUTTON onClick="ClipBoard1();">Copy Note</BUTTON> <p> <SCRIPT LANGUAGE="JavaScript"> function ClipBoard11() { holdtext11.innerText = copytext11.innerText; Copied11 = holdtext11.createTextRange(); Copied11.execCommand("Copy"); } </SCRIPT> <SPAN ID="copytext11" STYLE="height:*;width:250;background-color:White"> 5 Day Pending close Message Left on Voice Mail. </SPAN> <TEXTAREA ID="holdtext11" STYLE="display:none;"> </TEXTAREA> <BUTTON onClick="ClipBoard11();">Copy Note</BUTTON> <p> <SCRIPT LANGUAGE="JavaScript"> function ClipBoard10() { holdtext10.innerText = copytext10.innerText; Copied10 = holdtext10.createTextRange(); Copied10.execCommand("Copy"); } </SCRIPT> <SPAN ID="copytext10" STYLE="height:*;width:250;background-color:White"> xxxxxx. Unable to leave Voice Mail will contact again on </SPAN> <TEXTAREA ID="holdtext10" STYLE="display:none;"> </TEXTAREA> <BUTTON onClick="ClipBoard10();">Copy Note</BUTTON> <p> [code] Is there a way that I code not have to repate code ... can it be condinced. I need help in a form so that a radio button input sets 2 NAME values like NAME="name1" and NAME="name2" Since I don't think this is possible, I would by happy to copy the value of name1 to name2 via a script/vb/java, etc. Here's the code snippet I have that needs help. <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="business" value="99999999999"> <table border="0"> <tr><td><input type="radio" name="name1" value="25.00">Donate $25 <tr><td><input type="radio" name="name1" value="90.00">Donate $90 <td><td><input type="radio" name="name1" value="Other">Other Amount</td><td> <td>$</td><td><input type="text" name="name1"> </table> [Now, I need code to auto set NAME="name2" to always be the same value as "name1" above even if user re-selects choice] .. .. .. </form> Thanks Dave |