PDA

View Full Version : pasting from clipboard


mark_and_co
07-15-2002, 10:08 PM
Hey,

What I want to do is to press a button and that will paste the contents of the clipboard into a textbox.

Any-one know how to do this??

Mark

nolachrymose
07-16-2002, 01:06 AM
if(typeof(event.dataTransfer)!="undefined") {
document.onkeydown=function() {
if(event.keyCode==97)
document.formName.fieldName.value=event.dataTransfer.getData("Text");
}
}

Note: IE only.

Hope that helps!

Happy coding! :)

mark_and_co
07-16-2002, 06:52 AM
Hi,

Thinking about it, it would be better to set it up as the page loads. I've tried doing this myself but nothing happens, This is the code I have:

<script language="Javascript">
function HighlightAll2(theField) {
document.addbook.addbookid.value=event.dataTransfer.getData("Text");
}
</script>
<body onload="javascript:HighlightAll2('addbook.addbookid')">

Thanks in advance.
Mark

jkd
07-16-2002, 07:01 AM
I've never seen that way of doing it...

I seem to think that in IE, you could do:

document.addbook.addbookid.focus();
document.execCommand('Paste');

Dunno for sure though.

mark_and_co
07-16-2002, 07:18 AM
That worked great...

Thanks