JavaScript - Copy Text Area Contents To Clipboard?
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! Similar TutorialsHello. 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. 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? Hi Friends, I need a copy to clipboard functionality from a text area using javascript. I use Zclip for the purpose, but it will not work as needed . I attach my working code along with this .. pls open index.html in browser and try it . Do any one can pls give a javascript solution to copy textarea content to clipboard... Thanks, Anes 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 ?> 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! 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 Code: solved ! 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 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 As of right now I have a code that will work in IE but wont work in FireFox...go figure. Basically what I want to have happen is when you type in an area code it will provide an output in a predetermined area of the page. For Example: Input- 512 Output - Austin, TX The code that I have doesn't work with firefox and I was just wondering if there was a code that would allow that to happen. Thanks! Hi, I have a form setup so that selecting a radio button opens a specific text field. The problem is if the user starts to enter information, then switches to a different radio button (perhaps they chose the wrong radio to start), the text they already started to enter on the previous textfield doesn't get cleared. This will be a problem later when inserting to sql. Here is a summary of the code: Code: <head> <script type="text/javascript"> function doClick(objRad){ if (objRad.value=="0"){ document.getElementById("textbox").style.display='block'; } else{ document.getElementById("textbox").style.display='none'; } if (objRad.value=="1"){ document.getElementById("textbox1").style.display='block'; } else{ document.getElementById("textbox1").style.display='none'; } if (objRad.value=="2"){ document.getElementById("textbox2").style.display='block'; } else{ document.getElementById("textbox2").style.display='none'; } } </script> </head> <body> <form action="insert.php" method="post"> <p>Please choose the business type: <input type="radio" name="rad" value="0" onclick="doClick(this)"> Sole Proprietorship <input type="radio" name="rad" value="1" onclick="doClick(this)"> Partnership <input type="radio" name="rad" value="2" onclick="doClick(this)"> Corporation <div id="textbox" style="display:none"> <input type="text" name="txt"> This is my sole proprietorship info.</div> <div id="textbox1" style="display:none"> <input type="text" name="txt"> This is my partnership info.</div> <div id="textbox2" style="display:none"> <input type="text" name="txt">This is my corporation info. </div> </form> </body> Any help is appreciated, Thanks in advance! im clueless when it comes to javascript, but this is what im trying to find: i have a page that has multiple text areas, i also have 4 links that when clicked i want to add some predefined text into the active text area the one with the text cursor in? The Hyperlinks: Code: <a href="#sc">Shift Changed</a> | <a href="#ol">On Leave</a> | <a href="#ot">OverTime</a> | <a href="#ss">ShiftSwap</a> The textareas: PHP Code: <td><textarea name=details$i rows=4 align=absmiddle cols=16 value="$details[$i]\">$details[$i]</textarea></td> as you can see the textareas are created on the fly based on a php array. would anyone be willing to put some code together for this? or even give me the basics on how i can get the active textarea's name so i can pass that to a script that inserts into a given field? hey im new to javascript and im working in this function , i can't get it work here is my code PHP Code: <SCRIPT LANGUAGE="JavaScript"> function text(form1) { var j = document.form1.diary.value; j = j.italics(); document.form1.diary.value = j ; } </SCRIPT> whats the problem ? Hi, I am wanting to insert text into a text area when a button or link is clicked. I know how to replace the whole lot in the text area, but I want it to insert text where the flashing cursor is in the text box. (Like Wikipedia) If any one can help, Then I will be very, very greatfull. Thank You. 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?
I know how to make something function onclick(), but how can I make it so it copies the area of a textarea element, does Javascript have the ability to do this? Thanks for any help in advance. Hi world I have this code in my page PHP Code: <iframe name="ff1" src="http://playerplus.co.nu/ipp.php" ></iframe> how i copy the result in this iframe to text or to some variable but from iframe not direct from the URL "http://playerplus.co.nu/ipp.php" So I'm working with a code that I can't seem to get the translation to show up in the text area. The user is supposed to enter text in a text area on the left hand side, hit the translation button, and the translation will appear like a sentence in the right hand text area. I don't seem to be able to get anything to show up in the right hand text area........ I know that i'ts probably something very simple that I am not seeing because at this point I am brain dead. Code: phrases = [["hello","ahoy"],["pardon me","aaarrgghh"],["excuse me","aarrr"], ["hows it going","hows it goin"],["sir","matey"],["madam","proud beauty"], ["woman","beauty"],["children","sprogs"],["where is","whar be"], ["can you help me find","know ye"], ["is that","be that"],["how far is it to?","how many leagues to"], ["the","th'"],["my","me"],["your","yer"],["there","thar"], ["outstanding","outstandin"],["attractive","attractive"],["happy","horny"], ["dead","went t' Davy Jones' locker"],["restroom","head"],["restaurant","galley"], ["hotel","fleabag inn"],["pub","pub"],["I would like to","I be needin' t"], ["I desire","I desire"],["I wish I knew how to","I'm a hankerin' t"], ["my mother told me to","MeAhoy! ol' mum, bless her black soul, always tol' me t"], ["have a great dinner","have a great what crawled out o' t' bung hole"], ["have a cocktail","swill a pint or two o' grog"],["fall on the ground","fall on t' ground"], ["get drunk","get splice t' mainbrace"]]; function Translate(text) { for(var i = 0; i < phrases.length; i++) { var toReplace = new RegExp("\\b"+ phrases[i][0]+"\\b", "i"); var index = text.search(toReplace); while(index != -1) { text = text.replace(toReplace, phrases[i][1]); index = text.search(toReplace); } } return text; } Code: <div> <textarea id="first_text" style="float:left" id="task_list" rows="20" cols="53"></textarea> <button id="translated" width="50px" heigth="100px" ><img src="pirate2.gif" />Translation----></button> <textarea id="second_text" style="float:right" id="task_list" rows="20" cols="53"></textarea> </div> I am building an e-learning lesson in Lectora that will be deployed to a SCROM compatible learning management system. The lesson is converted into HTML before that happens. My table of contents is around 100 pixels wide but some of the page names are longer than that and do not display fully when viewed in a browser. What I am trying to do is this: The page name for this page is very, very long and I can't see it all. Blah blah Would become The page name for this page is very, very long and I can't see it all. Blah blah I've been led to believe there is javascript that will do that. Hi all, Please forgive me if this is a dumb question. Is it possible to highlight the contents of all text and/or textareas within one form simultaneously? I've tried to do it using the funciton below, it cycles through allright, but only highlights each field whilst it is in focus, then loses it when it moves to the next field. The result is that only the last text/textarea within the form is highlighted. My aim is to highlight all fields for subsequent spell checking. Any help would be appreciated. Code: <html> <head> <script type="text/javascript"> function SelectText(){ var fields = document.getElementsByTagName("input"); for (var i = 0; i < fields.length; i++){ var node = fields[i]; if (node.getAttribute('type') == "text"){ node.focus(); node.select(); } } } </script> </head> <body> <form id="form1" action=""> <p></p> <input type="text" id="one" style="width:500px;"> <p></p> <input type="text" id="two" style="width:500px;"> <p></p> <input type="button" value="Select Text" onclick="javascript:SelectText();"> </form> </body> </html> |