Jump to content

[SOLVED] Copy To Clipboard in Repeating Region


Zergman

Recommended Posts

Tried searching, didn't find anything that worked.

 

I have a repeating region that has 1 textarea in it.  What I want to do is add a "copy to clipboard" button so the user doesn't have to manually do it.

 

I got it working if there is one text area, but if there is more than one, it fails to work.

 

Here's what I got so far.

Script

<script language=javascript>
function copy(text) {
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text);
  }
}
</script> 

 

Form

<form name="form">
<table border="0" align="center" cellpadding="0" cellspacing="0">
<?php do { ?>
<tr>
<td><div align="right">Subject :</div></td>
<td><span class="style8"><?php echo $row_rscategories['subject']; ?></span></td>
</tr>
<tr>
<td><div align="right">Category :</div></td>
<td><?php echo $row_rscategories['category']; ?></td>
</tr>
<tr>
<td valign="top"><div align="right">Note :</div></td>
<td><textarea name="template" cols="60" rows="7" class="inputtextarea" id="template" readonly="readonly" onKeyDown="limitText(this.form1.template,this.form1.countdown,1000);" 
onKeyUp="limitText(this.form1.notes,this.form1.countdown,1000);"><?php echo $row_rscategories['template']; ?></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="right"><input type="button" class="inputbox" value="Copy To Clipboard" onclick="copy(document.form.template.value);"> | <?php echo $row_rscategories['status']; ?> Note - <a href="templates_edit.php?recordID=<?php echo $row_rscategories['id']; ?>">Edit</a></td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
<?php } while ($row_rscategories = mysql_fetch_assoc($rscategories)); ?>
</table>
</form>

 

Help?!

You need to correct your loop so that each element has a unique name and ID. Assuming each record has a unique ID, this should work:

 

<form name="form">
<table border="0" align="center" cellpadding="0" cellspacing="0">
<?php do { ?>
<tr>
<td><div align="right">Subject :</div></td>
<td><span class="style8"><?php echo $row_rscategories['subject']; ?></span></td>
</tr>
<tr>
<td><div align="right">Category :</div></td>
<td><?php echo $row_rscategories['category']; ?></td>
</tr>
<tr>
<td valign="top"><div align="right">Note :</div></td>
<td><textarea name="template<?php echo $row_rscategories['id']; ?>" cols="60" rows="7" class="inputtextarea" id="template<?php echo $row_rscategories['id']; ?>" readonly="readonly" onKeyDown="limitText(this.form1.template<?php echo $row_rscategories['id']; ?>,this.form1.countdown,1000);" 
onKeyUp="limitText(this.form1.notes,this.form1.countdown,1000);"><?php echo $row_rscategories['template']; ?></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="right"><input type="button" class="inputbox" value="Copy To Clipboard" onclick="copy(document.form.template<?php echo $row_rscategories['id']; ?>.value);"> | <?php echo $row_rscategories['status']; ?> Note - <a href="templates_edit.php?recordID=<?php echo $row_rscategories['id']; ?>">Edit</a></td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
<?php } while ($row_rscategories = mysql_fetch_assoc($rscategories)); ?>
</table>
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.