Click to See Complete Forum and Search --> : Copy to clipboard


kopite
04-06-2003, 10:50 AM
Hi,

I want to be able to copy certain rows (e.g. index rows 0 and 2) from a table to the clipboard, in comma delimited format.

html...

<table id="mytbl">
<tr><td>val1</td><td>val2</td><td>val3</td></tr>
<tr><td>vald</td><td>val99</td><td>val2</td></tr>
<tr><td>valx</td><td>val4</td><td>val2</td></tr>
</table>

clipboard..

val1,val2,val3
valx,val4,val2

How should I do this in JavaScript ?

Cheers

SniperX
04-07-2003, 05:35 AM
<object id="students" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83" width="0" height="0">
<param name="DataURL" value="students.txt" />
<param name="TextQualifier" value="," />
<param name="UseHeader" value="true" />
</object>
<table>
<tr>
<td>Name:</td>
<td><input type="text" datasrc="#students" datafld="Name" /></td>
</tr>
` <tr>
<td>Course:</td>
<td><input type="text" datasrc="#students" datafld="Course" /></td>
</tr>
<tr>
<td>Full/Part time:</td>
<td><input type="text" datasrc="#students" datafld="Full/Part" /></td>
</tr>
<tr>
<td>Age:</td>
<td><input type="text" datasrc="#students" datafld="Age" /></td>
</tr>
<tr>
<td>Average:</td>
<td><input type="text" datasrc="#students" datafld="Average" /></td>
</tr>
</table>

Where students.txt looks a like this:

Name, Course, Age:INT, Full/Part, Average:INT
Kobus,IDS, 26, F, 87
Greg,ITE, 23, P, 75
Alice,Comp Sci, 19, P, 65
Jill,IDS, 28, F, 72
Grant,IDS, 31, P, 86
Bill,ITE, 26, F, 72
Jessica,Comp Sci, 22, F, 73
Sandra,Comp Sci, 21, F, 88
Lindsey,IDS, 24, P, 81
Wayne,ITE, 19, F, 70
Brian,IDS, 28, F, 74
Jacques,ITE, 23, F, 85
Phillip,IDS, 24, P, 80
Thabo,ITE, 22, F, 86
Sindy,IDS, 26, F,12

Hope this example helps a bit

viravan
04-07-2003, 07:57 AM
I seriously doubt that you can put anything directly in the user's system clipboard via JavaScript... Even if you found a way to do it, you'll have to sign the script to overcome the sandbox thingy....

What you wanted to do can be easily done using either a signed or an unsigned Java Applet. You maybe able to use MS script if the target audience is mostly Windows users.

:)

V.V.

kopite
04-07-2003, 08:28 AM
Hi,

The users are pure IE, so I have found that this will work as needed, placing toCopy into the windows clipboard.

function copyToClipboard(toCopy)
{
window.clipboardData.setData('Text', toCopy)
}

:) :) :)

viravan
04-07-2003, 08:43 AM
Is this a JsScript ONLY feature or is it also available in JavaScript? Would it be affected by IE setting disallowing clipboard paste operation if the script is not signed?

:)

V.V.