470,604 Members | 2,014 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,604 developers. It's quick & easy.

Cut & Paste

I use these two functions for Copy & Paste with buttons in some text area
into a form:

<SCRIPT LANGUAGE="Javascript">

function copy(area){
var temp = eval("document." + area);
aa=temp;
window.clipboardData.setData('Text',aa);
}

function paste(area2){
var temp2 = eval("document." + area2);
bb=window.clipboardData.getData('Text');
temp2 = bb;
}
</SCRIPT>
</head>
If i call the Copy function (dinamically with php) with a parameter like:
form1.text1.value it works fine, but with the Paste function doesn't work.
I think the problem is in the evaluate statement of the parameter area2.

Anyone can help me ?? Thanks

Simone
Jul 23 '05 #1
3 4255
Simo wrote on 28 apr 2004 in comp.lang.javascript:
<SCRIPT LANGUAGE="Javascript">

function copy(area){
var temp = eval("document." + area);
aa=temp;
window.clipboardData.setData('Text',aa);
}

function paste(area2){
var temp2 = eval("document." + area2);
bb=window.clipboardData.getData('Text');
temp2 = bb;
}
</SCRIPT>


Try this:

<div id=from>qwerty</div>
===========================
<div id=to>asdfg</div>

<script type="text/javascript">

function copy(area){
var temp = document.getElementById(area);
window.clipboardData.setData('Text',temp.innerHTML );
}

function paste(area){
var temp = document.getElementById(area);
temp.innerHTML = window.clipboardData.getData('Text');
}

copy("from")
paste("to")
</script>

Tested IE6

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #2
Simo wrote:
I use these two functions for Copy & Paste with buttons in some text area
into a form:

<SCRIPT LANGUAGE="Javascript">

function copy(area){
var temp = eval("document." + area);
aa=temp;
window.clipboardData.setData('Text',aa);
}

function paste(area2){
var temp2 = eval("document." + area2);
bb=window.clipboardData.getData('Text');
temp2 = bb;
}
</SCRIPT>
</head>
If i call the Copy function (dinamically with php) with a parameter like:
form1.text1.value it works fine, but with the Paste function doesn't work.
I think the problem is in the evaluate statement of the parameter area2.

Anyone can help me ?? Thanks

Simone


Wow... where do I start?

1. Do not use LANGUAGE. Instead, use TYPE
2. Do not use eval(). There are always better ways to do it
3. Dont make so many temp variables. It makes it hard to read
4. clipboardData only works in IE 5+. I dont know if anything like this
exists in other browsers.

Try something more like this. Of course, modify it for a better set of
what you need, but this should give you a good start.

-- Brian

<HTML>
<HEAD>
<SCRIPT type="text/javascript">

function copy(source){
window.clipboardData.setData("Text",
document.getElementById(source).value);
}

function paste(dest){
document.getElementById(dest).value =
window.clipboardData.getData("Text");
}

function CopyAndPaste( from, to )
{
copy(from); paste(to);
}

</SCRIPT>
</HEAD>

<BODY>
<FORM action="submit.asp">
<INPUT TYPE=text name=text1>Text 1<BR>
<INPUT TYPE=text name=text2>Text 2<BR>
</FORM>

<BUTTON onClick="CopyAndPaste('text1', 'text2')">
Copy and Paste
</BUTTON>

</BODY>
</HTML>

Jul 23 '05 #3
Brian Genisio wrote:

4. clipboardData only works in IE 5+. I dont know if anything like this
exists in other browsers.


IE 5+ Windows!
Mick.

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by William Gill | last post: by
1 post views Thread by Tomomichi Amano | last post: by
6 posts views Thread by NuB | last post: by
26 posts views Thread by Robert Baer | last post: by
14 posts views Thread by Arne | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.