Solved

ZeroClipboard not working after php processes the page

Posted on 2011-03-22
1
537 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
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 …

820 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