Solved

ZeroClipboard not working after php processes the page

Posted on 2011-03-22
1
525 Views
Last Modified: 2012-05-11
I'm using php to dynamically create rows based on values from a database. At the end of each row I want to include functionality to copy the contents of that row to the clipboard.

I have working copy-to-clipboard code here:
		                        <script language="JavaScript">
						function cboard(text)
						{
                        var clip = new ZeroClipboard.Client();
						clip.setText(text);
                        clip.glue( 'd_clip_button' );
						}
                </script>
<script type="text/javascript" src="ZeroClipboard.js"></script>
                <div id="d_clip_button" onMouseOver="cboard('party');" style="border:1px solid black; padding:20px;">Copy To Clipboard</div>
                        

Open in new window


however, when I process it via php and output the page like so:


			$result = mysql_query("SELECT * FROM `backup` ORDER BY `id` ".sort_order()." LIMIT ".($logspage*$_SESSION["page"])." , ".$logspage.";", $mysql);
			if (!$result) die(mysql_error());
			
			$html .= "Logs".$header.$javascript."
					<form name='frm' method='POST' action='?action=selected' onsubmit='return checkform();'>
					<table id='logstable' cellpadding='2' cellspacing='0' border='0'><tr id='row0'>
					<td><a href='?action=logs&sort=0'>name/ ref</a></td>
					<td><a href='?action=logs&sort=1'>date</a></td><td><a href='?action=logs&sort=2'>password</a></td>
					<td><a href='?action=logs&sort=3'>website</a></td><td><a href='?action=logs&sort=4'>ip</a></td>
					<td><input type='checkbox' name='check_all' onClick='checkAll();'></td></tr>";
			$i = 0;
			while ($row = mysql_fetch_array($result)) {
				$html .= "<tr class='";
				if ($i % 2 == 0) $html .= "row1"; else $html .= "row2";
				$html .= "'><td>".$row["ref"]."</td>";
				$html .= "<td>".$row["name"]."</td><td>".$row["pass"]."</td><td>".$row["ip"]."</td>";
				$html .= "<td>".$row["date"]."</td>";
				$html .= "<td><input type='checkbox' name='sel[]' value='".$row["id"]."'><div id=\"d_clip_button\" onMouseOver=\"cboard('".$row["website"]."');\"><b>Copy</b></div></td></tr>";
				$i++;
			}

Open in new window


a working ZeroClipboard element is ONLY included on the FIRST ROW. all subsequent rows below the first are just plain-text "Copy" without the underlying necessary element that ZeroClipboard creates.

Does ZeroClipboard work like this? Or is it limited to only statically created pages? Or am I just doing something wrong in my dynamic ZeroClipboard implementation?


Thank you!
0
Comment
Question by:JoeD77
1 Comment
 
LVL 17

Accepted Solution

by:
shinuq earned 500 total points
ID: 35204531
actually there aer multiple creation of the tag "d_clip_button" hence the script confuses which one to use.

Below we have added a number to the d_clip_button tag which make it unique in the page

Hope this helps
<script language="JavaScript">
function cboard(text,id)
{
  var clip = new ZeroClipboard.Client();
       clip.setText(text);
       clip.glue( 'd_clip_button_'+id);
}
</script>


<div id=\"d_clip_button_$i\" onMouseOver=\"cboard('".$row["website"]."',$i);\">

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Creating a slider 12 34
while loop in html mail format 5 32
XML Data Missing in PHP SimpleXML 8 23
Glyph icons in Bootstrap 3 4 14
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now