JavaScript - Append Additional Text To Selected Text When Copy To Clipboard?
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. Similar TutorialsHello, 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! 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? 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 ?> like for example i have text areas named upload1 and upload2 when I click or add input on upload1 a drop down list below upload2 will not change, but when I add input on upload2 the dropdown will select "parts" Code: solved ! 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 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 am attempting to manipulate a long text string with javascript. This text string may have one or more occurrences of a string which starts with a particular string and ends with another string. So, for example, text that starts with 'nam' and ends with 'sit' in this example: Quote: Lorem ipsum dolor sit amet, consectetur adipiscing elit nam aliquam leo sit amet nibh tincidunt ultricies. Nullam nam feugiat velit sit amet dui scelerisque id ornare nulla ultricies. I want to prepend another string before the nam and append another after the sitt, to give me: Quote: Lorem ipsum dolor sit amet, consectetur adipiscing elit before nam aliquam leo sit after amet nibh tincidunt ultricies. Nullam before nam feugiat velit sit after amet dui scelerisque id ornare nulla ultricies. I think the way to do this is via RegExp, but I'm insufficiently familiar with this to know how to write the expression. Can anyone help me out? 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 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" 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 I have a select box with a few options. When the page loads I need to get the selected option in this select box and alert its inner text. Yet everything I try out on the net that should work wont work in IE, all other browser its fine. Please can someone show me the TRUE and correct way to get the inner text of a option from a select box in IE? Thanks! I retrieve a list of links from a database using ajax, then I assign them to the innerHTML property of a div whose display property is set to "none" Then I set the display property to "display" to get a drop-down listbox. The problem is the links in the list are all hilighted like they've been dragged over by a mouse. How do I prevent these links from highlighting? I searched about this problem over Internet and found the same result many times, I found this example on stack overflow but this example didn't work in my project; I am making a toolbar with buttons that insert HTML tags around the selected text in a <textarea>, this exemple didn't work because when the user click on a button the selected text won't be selected anymore because <textarea> loses focus and selected text will be unselected, I am targeting Firefox and compatible browsers so you don't need to give me the IE code; jQuery codes are accepted; so, have you any idea?
How can I get the selected text of a textarea with JavaScript? example: Code: <form name="reportForm"> <textarea name="report"></textarea> <br /> <input type="button" onClick="GetSelectedText();" /> </form> Thanks IC HI all, I am new to this forum and really needs your help. Please let me know how can I highlight a selected portion of an html document with javascript such that the selected portion is repeatedly shown highlighted on each and every page refresh. Thanks & Regards, Sumantra Hi, Can somebody help me with the coding. I have a long list of events and I want somebody to be able to select one of those events & there will be a text box that shows the address pertaining to the event selected. Exactly how this website did he http://svacpa.com/live-webinars-and-...-registration/ Please advise! Thanks -------------- Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MySite Registration</title> </head> <body> <div style="width: 900px"> <p>Registration</P <form method="post" action="http://mysite.com" name="Registration"> <label id="Label1">First Name</label><input name="FirstName" type="text" /><br /><br /> <label id="Label1">Last Name</label><input name="LastName" type="text" /><br /><br /> <label id="Label2">Title</label><input name="Title" type="text" /><br /><br /> <label id="Label3">Company</label><input name="Company" type="text" /><br /><br /> <label id="Label5">Email</label><input name="Email" type="text" /><br /><br /> <label id="Label4">Phone</label><input name="Phone" type="text" /><br /><br /> <input name="Radio1" type="radio" class="input" /><label id="Label1" class="lableinput">San Francisco, Wednesday, March 16 Breakfast</label><br /><br /> <input name="Radio1" type="radio" class="input" /><label id="Label1" class="lableinput">San Francisco, Wednesday, March 16 Lunch</label><br /><br /> <input name="Radio1" type="radio" class="input" /><label id="Label1" class="lableinput">Santa Clara, Friday, March 18 Lunch</label><br /><br /> <input name="Radio1" type="radio" class="input" /><label id="Label1" class="lableinput">Santa Clara, Friday, March 18 Dinner</label><br /><br /> <br /> <input name="Submit1" type="submit" value="Register Now" class="submit" /> <input type="hidden" name="redirect" value="http://www.mysite.com/regsuccess.html"/> <input type="hidden" name="recipient" value="me@mysite.com"/> <input type="hidden" name="required" value="FirstName, LastName, Email, Phone"/> <input type="hidden" name="missing_field_redirect" value="http://mysite.com/regerror.html"/> </form> </div> </body> </html> |