Click to See Complete Forum and Search --> : clipboard function
tripwater
11-13-2003, 05:09 PM
I have some info that needs to be set to the clipboard. I am currently using a function that requires you to click the item inside a span and it is visible to everyone.
How can I take the code below and when the page loads, assign $tempid to the clipboard automatically, and keep it hidden from view?
<SCRIPT LANGUAGE=\"JavaScript\" type=\"text/javascript\">
function addClip1()
{
holdtext.innerText = copytext1.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand(\"Copy\");
}
</script>
<!--here is our fields necessary to hold/hide what we are copying to clipboard-->
<span id=\"copytext1\" style=\"display:none;\">
(".$tempid.")</span>
Thank you for any help.
Khalid Ali
11-13-2003, 05:43 PM
when you create a text range it will select the text.What you need to do is get the innerHTML/innerText/nodeValue etc for the element then put it on the clipbaord
tripwater
11-14-2003, 08:08 AM
Thanks for the reply. I am not one usually to ask someone to write my code for me, but can you show me what you mean? I am still at a basic level (self teaching) of Javascript and do not know how to take the next steps with what you gave.
Would I need to get rid of the span I have around my text?
How would I call the function?
Thank you again.
tripwater
11-14-2003, 09:10 AM
I tried this, and it is obviously wrong because of my lack of JS knowledge.
<script>
function addClip1()
{
holdtext.innerText = innerHTML.innerText.copytext1.value;
Copied = holdtext.createTextRange();
Copied.execCommand(\"Copy\");
}
</script>
I read up some on the innerText and innerHtml and from what I gather , anything in a tag like
<div id=div1>some text<h2>A heading</h2></div>
The value of the inner HTML for div1 would be
Some text <h2>A heading</h2>
Only I do not know how to apply it with what I am doing because quite honestly I don't thoroughly understand my code as I found it somewhere and it was close to what I needed. I have been trying to study it and make sense but most of what I try fails.
Thanks again.
tripwater
11-14-2003, 09:19 AM
Just a side note I do not think the direction I am headed is all correct. I failed to explain (and I apologize) the full functionality I am going for.
I have a shopping cart that wil interface to a BSV (business program). What I need is, say if we are on the final page that displays the cart items and has a finish button, I need when the user clicks the finish button, it write all of the item numbers as well as their quantities delimited by a "|" into the clipboard so we can then take this info and paste it into the program and continue processing.
so it would look like item123|2|item1234|3|item12345|1
I hope this explains my objective, again sprry for the lack of info from the start.
Thanks
tripwater
11-14-2003, 10:00 AM
Here is my basic HTML example page. If you could tell me or point me in the direction as to how to get each itemno and its quantity into the clipboard , delimited by "|" when you hit next, I would be very grateful Thanks.
<html>
<head>
<title>Test Cart</title>
</head>
<body>
<table width =800 cellpadding=0 cellspacing=3 border=0>
<tr>
<td colspan=5 align=center>
<b><u>Your Shopping Cart</u></b><br><br>
</td>
</tr>
<tr>
<td>
<b><u>Item NO.</u></b>
</td>
<td>
<b><u>Item Description</u></b>
</td>
<td>
<b><u>Quantity</u></b>
</td>
<td>
<b><u>Unit Price</u></b>
</td>
<td>
<b><u>Extended Price</u></b>
</td>
</tr>
<tr>
<td>
item123
</td>
<td>
Golf Shirt
</td>
<td>
1
</td>
<td>
$12.95
</td>
<td>
$12.95
</td>
</tr>
<tr>
<td>
item1234
</td>
<td>
Golf Shoes
</td>
<td>
1
</td>
<td>
$55.00
</td>
<td>
$55.00
</td>
</tr>
<tr>
<td>
item12345
</td>
<td>
Golf Hat
</td>
<td>
3
</td>
<td>
$11.00
</td>
<td>
$33.00
</td>
</tr>
</table>
<table cellspacing="0" cellpadding=0 border=0 width=650>
<tr>
<td colspan=5 align=right>
<b>Total :</b> $100.95
</td>
</tr>
<tr>
<td colspan=5 align=right>
<br><br><img src=../images/next.gif border=0>
</td>
</tr>
</table>
</body>
</html>