Zergman Posted January 12, 2009 Share Posted January 12, 2009 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 https://forums.phpfreaks.com/topic/140545-solved-copy-to-clipboard-in-repeating-region/ Share on other sites More sharing options...
Psycho Posted January 12, 2009 Share Posted January 12, 2009 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 https://forums.phpfreaks.com/topic/140545-solved-copy-to-clipboard-in-repeating-region/#findComment-735476 Share on other sites More sharing options...
Zergman Posted January 12, 2009 Author Share Posted January 12, 2009 Worked like a charm. Makes sense now that I see what you did. Thanks a million! Link to comment https://forums.phpfreaks.com/topic/140545-solved-copy-to-clipboard-in-repeating-region/#findComment-735508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.