?
Solved

ZeroClipboard not working after php processes the page

Posted on 2011-03-22
1
Medium Priority
?
545 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 17

Accepted Solution

by:
Shinesh Premrajan earned 2000 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

800 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