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>