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?!

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.