The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> button to select table, JS or HTML button to select/copy
rstephen
post Jun 29 2015, 01:55 PM
Post #1





Group: Members
Posts: 1
Joined: 29-June 15
Member No.: 22,787



I have plenty (>40 years) programming experience, but am relatively new to HTML and JS. So the answer to this may be intuitively obvious to the most casual observer. So call me "dummy".
I have a page - the stripped-down version is below - that contains a table (which was generated with php from a mySQL database, but that is not relevant). I want to add a button that will select/copy the table to the clipboard. Two buttons are okay, too. This doesn't seem complicated, but I have been unsuccessful. We've been using ctl-A/ctl-C, but I would like something more elegant.

= THE PAGE ==========================================================================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<table cellspacing="2" cellpadding="2" border="1">
<tr><td>1</td><td>Samantha</td><td>Jones</td><td>123 West Main</td><td>Hoboken</td><td>NJ</td><td>12345-6789</td><td>none@nowhere.com</td><td>5555860123</td><td>2015-05-16</td></tr>
<tr><td>37</td><td>Arnold</td><td>Smith</td><td>10 Leafy Lane</td><td>Hammonton</td><td>TX</td><td>08690-1358</td><td>al@yahoo.com</td><td></td><td>2015-05-20</td></tr>
</body>
</html>
================================================================================
====


Thanks for any help.

- Robert
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jun 29 2015, 04:29 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



This sounds like javascript so I move the thread there.

QUOTE(rstephen @ Jun 29 2015, 08:55 PM) *

I want to add a button that will select/copy the table to the clipboard.

Do you mean selecting both the table's markup and text, or just its text content?

Also, selecting and copying text are two separate operations (making text appear selected might be user-friendly, but I don't think it's technically required in order to copy text to the clipboard). Here's an example on how to select text: http://stackoverflow.com/a/987376 (the script after the "Edit" line). Copying text to the user's clipboard seems much harder due to security restrictions, some ideas are discussed here: http://stackoverflow.com/questions/400212/...d-in-javascript


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 11:23 AM