Forum : Can We Invoke Keyboard Events On Button Press ?
Brief description  about Online courses   join in Online courses
View Anonymous  Anonymouse 's Profile

Can We Invoke Keyboard Events On Button Press ?

i'm unable to copy from textarea 1 to textarea 2 with the help to push buttons "COPY" and "PASTE".... in firefox 3.6
Asked by Anonymous Anonymouse | Aug 16, 2010 |  Reply now
Replies (2)
View anonymous anonymouse 's Profile
well this code might be useful for IE lovers and it also works for IE8

<head>
<script type="text/javascript">
var myClipboard = "";

function Copy () {
var src = document.getElementById ("src");
if (src.selectionStart === undefined) { // Internet Explorer
// you have done it in IE 7
}
else { // Firefox, Chrome, Opera and Safari
myClipboard = src.value.substring (src.selectionStart, src.selectionEnd);
}
}

function Paste () {
var dest = document.getElementById ("dest");
if (dest.selectionStart === undefined) { // Internet Explorer
// you have done it in IE 7
}
else {
# var newValue = dest.value.substring (0, dest.selectionStart);
newValue += myClipboard;
newValue += dest.value.substring (dest.selectionEnd);

dest.value = newValue;
}
}
</script>
</head>
<body>
<textarea id="src" cols="30">Select some text and use the copy and paste buttons to insert it into the second textarea.</textarea>
<br /><br />
<button onclick="Copy ()">Copy</button>
<button onclick="Paste ()">Paste</button>
<br /><br />
<textarea id="dest" cols="30"></textarea>
</body>.
Aug 17, 2010
View teacher siliconindia 's Profile
Hi Arun,

Clipboard access is not always allowed in Firefox,because of security restrictions.

One way to acheive this is to store the selected text in a JavaScript variable on copy and insert its value on paste but the user cannot use CTRL+V to paste the text into TextArea2,as it is not on the clipboard.
Aug 17, 2010