JavaScript - Test Copy To The Clipboard Can't Work?
Code:
solved ! Similar TutorialsHey 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, 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. 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 Hi All, I am looking to make a "enemy" dissapear when "character" hits it? I don't really know what I'm doing. All help is appreciated! PHP Code: <!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> <style> body { padding:0; margin:0; background:#000; } canvas { display:block; margin:30px auto 0; border:1px solid #ccc; background:#999; } </style> <script> var canvas, ctx, width = 320, height = 480, rightKey = false, leftKey = false, enemyTotal = 4, enemies = [], enemy_x = 50, enemy_y = 1, enemy_w = 32, enemy_h = 32, speed = 1, character_x = (width / 2) - 15, character_y = height - 65, character_w = 32, character_h = 32, level_1, level_1_bgX = 0, level_1_bgY = -1312; var enemy, character; for (var i = 0; i < enemyTotal; i++) { enemies.push([enemy_x, enemy_y, enemy_w, enemy_h, speed]); enemy_x += enemy_w + 30; } function drawEnemies() { for (var i = 0; i < enemies.length; i++) { ctx.drawImage(enemy, enemies[i][0], enemies[i][1]); } } function moveEnemies() { for (var i = 0; i < enemies.length; i++) { if (enemies[i][1] < height) { enemies[i][1] += enemies[i][4]; } else if (enemies[i][1] > height - 1) { enemies[i][1] = -45; } } } function clearCanvas() { ctx.clearRect(0,0,width,height); } function drawCharacter() { ctx.drawImage(character, character_x, character_y); if (rightKey) character_x += 5; else if (leftKey) character_x -= 5; if (character_x <= 0) character_x = 0; if ((character_x + character_w) >= width) character_x = width - character_w; } function drawlevel_1() { ctx.drawImage(level_1,level_1_bgX,level_1_bgY); if (level_1_bgY > 1792) { level_1_bgY = -1791; } level_1_bgY += 1.5; } function init() { canvas = document.getElementById('canvas'); ctx = canvas.getContext('2d'); enemy = new Image(); enemy.src = 'character_1.gif'; character = new Image(); character.src = 'character_1.gif'; level_1 = new Image(); level_1.src = 'level_1.jpg'; setInterval(gameLoop, 25); document.addEventListener('keydown', keyDown, false); document.addEventListener('keyup', keyUp, false); } function gameLoop() { clearCanvas(); drawlevel_1(); moveEnemies(); drawEnemies(); drawCharacter(); } function keyDown(e) { if (e.keyCode == 39) rightKey = true; else if (e.keyCode == 37) leftKey = true; } function keyUp(e) { if (e.keyCode == 39) rightKey = false; else if (e.keyCode == 37) leftKey = false; } window.onload = init; </script> </head> <body> <canvas id="canvas" width="320" height="480"></canvas> </body> </html> Thanks hello guys, I'm new here .. I am developing a fw js, now I have to test the selector $.. operation is similar to jquery $('#Id') $('table td .class) If there are several factors you should: $('table td .class).each(function () { this .. }); or $('table td .class).item(number) ... http://debbe.altervista.org/d&d.html can be used to test the methods set / get the attributes or setCSS or getCSS for styles .. Thanks to all I've gone far enough with my website and thanks to you guys i completed a lot of issues i had. I just included a browser detect snippet which is supposed to show the pages correctly on IE, Firefox, Safari, Opera and Chrome. I understand that watching a greek site won't make much sense for you, but i'm hoping you will at least understand how the thing goes. The first yellow box on your left is the menu. Clicking there will take you to the menu's categories. You will find a few categories in english there, at least Now, in each category, clicking the button below the product should put it in the cart, part of it appears on every page in a floating layer to the top-right. There is also a link in there to "checkout" (ΟΛΟΚΛΗΡΩΣΗ ΠΑΡΑΓΓΕΛΙΑΣ). This is where the problem comes: In every browser except Chrome, the list of items of the cart will appear. I don't know why but in Chrome, not only i see nothing in there, but it also deletes everything in the cart! If any of you, specially the ones who have many browsers installed, could spend a little time testing my site, i would really appreciate it. Old Pedant and Phillip should be more aware since you guys have already helped me out and you kinda know the functionality of the site. The address is: lukulos.gr (works directly now, no need to type specific files) Code: <html> <head> <script> function testemail(){ var fld= document.getElementById("input1").value; var reg = /^[\w+]@[\w+].com$/i; if(reg.test(fld)) { alert("email is ok"); } else { alert("email is not correct"); } } </script> </head> <body> <p> <form name="form1" onsubmit="testemail()"> enter email : <input id="input1" type="text" /> <input id="input2" type="submit" value="Submit" /> </form> </p> </body> </html> I am trying to test an email ID with above RegExp. I enter a correct email or not, I am always getting message "email is not correct" So RegExp is not working. How can I find out whats wrong with this RegExp ? Is there any tool to figure that out ? I tried with FireBug, but it does not point to whats wrong with RegExp Thanks Code: //Script to Rotate Images and Transition Effects var slidespeed=2000 var slideimages=new Array("1.jpg","2.jpg","3.jpg") var whichimage=0 var imgobj, filtersupport, blenddelay var imageholder=new Array() for (i=0;i<slideimages.length;i++){ //preload images imageholder[i]=new Image() imageholder[i].src=slideimages[i] } function slideit(){ if (filtersupport) imgobj.filters[0].apply() imgobj.src=imageholder[whichimage].src if (filtersupport) imgobj.filters[0].play() whichimage=(whichimage<slideimages.length-1)? whichimage+1 : 0 setTimeout("slideit()", slidespeed+blenddelay) } //End Image Rotation/Transistion What object can I test for instead of "filtersupport" so that I can have an else {} for non-ie browsers? I have Javascript on my site and will not work at all if JS is disabled. How do I notify my users that the pull down menus use javascript and will not work unless they turn it on? Can someone advise me how I could get this websocket to work. I'm working off a tutorial which gives this example. Code: var connection = new WebSocket('ws://html5rocks.websocket.org/echo', ['soap', 'xmpp']); // When the connection is open, send some data to the server connection.onopen = function () { connection.send('Ping'); // Send the message 'Ping' to the server }; // Log errors connection.onerror = function (error) { console.log('WebSocket Error ' + error); }; // Log messages from the server connection.onmessage = function (e) { console.log('Server: ' + e.data); }; This does work and I can write something similar can get the correct results as long as I am connecting to that address. I am not able to get the same results from my server and I cannot even get the sockets onopen function to run. Here is my JS Code- Code: socket = new WebSocket("ws://micahwilliamson.com:80/socket.php", ['soap', 'xmpp']); socket.onmessage = function(e) { alert(e.data); } socket.onopen = function() { alert("Success"); socket.send("test"); } socket.onerror = function(err) { alert(err); } Here is my php socket code. Code: <?php ini_set("display_errors", 1); $host = "localhost"; $port = 80; $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket"); $bind = socket_bind($socket, $host, $port) or ("Could not bind to socket"); $listen = socket_listen($socket, 3) or die("Could not listen to socket"); $spawn = socket_accept($socket) or die("Could not accept incoming connection"); $input = socket_read($spawn, 1024) or die("Could not read input"); $input = trim($input); $output = strrev($input); socket_write($spawn, $output, strlen($output)) or die("Could not write to socket"); socket_close($spawn); socket_close($socket); ?> It seems the socket cannot make a connection so it could be my php code or the file hosting server just wont allow it. I got a VPS- maybe that would work better? Hello! I am trying to validate name, email and comment inputs! I did the following! Code: $("#CmtSub").click(function(event){ var email = $("#CmtEmail").val(); var filter = /'^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$'/; if( $("#CmtName").val() == "" ){ $("#CmtName").css({'background-position': '0 -45px'}, 0); return event.preventDefault(event); }else{ $("#CmtName").css({'background-position': '0 -90px'}, 0); } if(filter.test(email) && email != "") { $("#CmtName").css({'background-position': '0 -45px'}, 0); return event.preventDefault(event); }else{ $("#CmtName").css({'background-position': '0 -90px'}, 0); } //just to debug console.log("the value and the email ("+ email +")"); if( $("#CmtTxtArea").val() == "" ){ $("#CmtTxtArea").css({'border': 'red 1px solid'}, 0); return event.preventDefault(event); }else{ $("#CmtTxtArea").css({'border': 'white 1px solid'}, 0); } // then proceed ! }); this code here isn't working! any help please ?: Code: if(filter.test(email) && email != "") { //passme = false; $("#CmtName").css({'background-position': '0 -45px'}, 0); return event.preventDefault(event); }else{ //passme = true; $("#CmtName").css({'background-position': '0 -90px'}, 0); } help is greatly appreciated ! Hello, I am trying to complete a test site but adding some javascript. In short I am trying to make the main content div slide from behind the nav via some JS. http://www.squareflash.com/test/index.html First I am just trying to get the animate onClick to work. I found this practice site -- Using this I am trying to get some guidance on how to add a automatic stop function to the moveRight variable. http://www.tutorialspoint.com/cgi-bi...=javascript_45 The site is in html5, is there anything special I need to know for that? ty Hello, I am trying to write a javascript page that shuffles an array of questions ( 1x1 , 1x2, 1x3 - 1x12), prints them, then has the user type in the answer, then checks them to make sure the user answer is correct. I have looked up a lot of source code for javascript "quiz" but they all are multiple choice answers and the questions are not shuffled. This is as far as I have gotten, but now I am not sure how to take the user input text and compare them to the answer / question array to make sure to check. Code: <html> <head> <title> Slick Math </title> <script type="text/javascript"> var quest = new Array; var ans = new Array; var questprint = new Array; quest[0] = "1 x 1 "; quest[1] = "1 x 2 "; quest[2] = "1 x 3 "; quest[3] = "1 x 4 "; quest[4] = "1 x 5 "; quest[5] = "1 x 6 "; quest[6] = "1 x 7 "; quest[7] = "1 x 8 "; quest[8] = "1 x 9 "; quest[9] = "1 x 10 "; quest[10] = "1 x 11 "; quest[11] = "1 x 12 "; questprint[0] = quest[0]+"<input type='text' name='q0'></input><br/>"; questprint[1] = quest[1]+"<input type='text' name='q1'></input><br/>"; questprint[2] = quest[2]+"<input type='text' name='q2'></input><br/>"; questprint[3] = quest[3]+"<input type='text' name='q3'></input><br/>"; questprint[4] = quest[4]+"<input type='text' name='q4'></input><br/>"; questprint[5] = quest[5]+"<input type='text' name='q5'></input><br/>"; questprint[6] = quest[6]+"<input type='text' name='q6'></input><br/>"; questprint[7] = quest[7]+"<input type='text' name='q7'></input><br/>"; questprint[8] = quest[8]+"<input type='text' name='q8'></input><br/>"; questprint[9] = quest[9]+"<input type='text' name='q9'></input><br/>"; questprint[10] = quest[10]+"<input type='text' name='q10'></input><br/>"; questprint[11] = quest[11]+"<input type='text' name='q11'></input><br/>"; var score = 0; ans[0] = 1; ans[1] = 2; ans[2] = 3; ans[3] = 4; ans[4] = 5; ans[5] = 6; ans[6] = 7; ans[7] = 8; ans[8] = 9; ans[9] = 10; ans[10] = 11; ans[11] = 12; function shuffle() { return (Math.round(Math.random())-.5); } questprint.sort(shuffle); </script> </head> <body> <h1>Slick Math</h1> <form name="form"> <script type="text/javascript"> document.write(questprint[0]); document.write(questprint[1]); document.write(questprint[2]); document.write(questprint[3]); document.write(questprint[4]); document.write(questprint[5]); document.write(questprint[6]); document.write(questprint[7]); document.write(questprint[8]); document.write(questprint[9]); document.write(questprint[10]); document.write(questprint[11]); </script> </form> </body> </html> Thanks =] When looping thru a group of elements and using getNamedItem('itemname').value there are some elements that are going to have a null value for that particular getNamedItem... the problem is that you cannot test this value to see if it's null because it generates an error instead, and the code does not continue: _allnames[_j].attributes.getNamedItem("onchange") is null You cannot even test it for null like this: if (_allnames[_j].attributes.getNamedItem("onchange").value != null) { do something } This will also generate an Error instead of testing to see if it is null. How do you test getNamedItem for null to avoid this error? EDIT: It appears that the problem is limited to Firefox. It works fine in IE7, but the error occurs in both FF v3.5.4 and in v3.5.5! Thanks In my example below, there are no elements that match, so you should see an alert box that says 'No match', but (using Firebug) you will see that an error is generated when it tries to find the value of onchange in the last input tag. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="generator" content="PSPad editor, www.pspad.com"> <title></title> <script type="text/javascript"> function myLoad() { //Add some text beside the Zip/Postal Code box var _match = false; var _cell = 0; var _allnames = document.getElementsByName('zip_code'); //Get all the TD tags var _len = _allnames.length; //How TD tags are there? for (_j=0; _j<_len; _j++) { //Loop thru each child _nodetype = _allnames[_j].nodeType; _name = _allnames[_j].attributes.getNamedItem('name').value; _onchange = _allnames[_j].attributes.getNamedItem('onchange').value; _type = _allnames[_j].attributes.getNamedItem('type').value; _size = _allnames[_j].attributes.getNamedItem('size').value; if (_nodetype == 1) { if ( (_name == 'zip_code') && ( _onchange == 'zip_changed();') && (_type == 'text') && (_size == '10') ) { //Look for these specific things to get the correct node (INPUT tag in this case) _match = true; alert('Match found'); var _old_node = _allnames[_j]; //This is the INPUT tag we were looking for var _new_node = document.createTextNode(' Enter NONE if this does not apply'); //This is the text we will add on the end of it _allnames[_j].parentNode.insertBefore(_new_node, _old_node.nextSibling); //insertBefore inserts before the element, but using targetElement.nextSibling inserts it after instead (insertAfter is deprecated)!! } } } if (_match != true) { alert('No match'); } } </script> </head> <body onLoad="myLoad();"> <table class="zipncountry" border="1"> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> </table> <br> <table border="3"> <tr> <td>4<input type="hidden" value="" ></td> <td>5</td> <td><input type="text" name="zip_code" value="123" size=11 maxlength=20 onChange="zip_changed();"><input type="hidden" name=zip_code value="321" maxlength=20 ></td> </tr> </table> <br> <table class="zipncountry" border="5"> <tr> <td>7</td> <td>8</td> <td>9</td> </tr> </table> </body> </html> |