Solved

ZeroClipboard not working after php processes the page

Posted on 2011-03-22
1
532 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:
Shinesh Premrajan 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

813 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

11 Experts available now in Live!

Get 1:1 Help Now