Click to See Complete Forum and Search --> : Using Java to paste from clipboard to a textbox


danowat
09-04-2003, 02:51 AM
Hi,

I have found a script that will almost do what I want.
In this script it will paste highlighted text into a window.
I would like to modify it to paste text from the clipboard.
How would I do this?.

I paste the script here.

Thank you

Dan.

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original: Raul Macias (raulhmacias@cox.net ) -->
<!-- Web Site: http://members.cox.net/raulhmacias/ -->
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function copyit(theField) {
var selectedText = document.selection;
if (selectedText.type == 'Text') {
var newRange = selectedText.createRange();
theField.focus();
theField.value = newRange.text;
} else {
alert('select a text in the page and then press this button');
}
}
// End -->
</script>

</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original: Raul Macias (raulhmacias@cox.net ) -->
<!-- Web Site: http://members.cox.net/raulhmacias/ -->
<form name="it">

<p>This script allows you to select text on a web page and then copy it into a text box. Neat!</p>
<div align="center">
<input onclick="copyit(this.form.select1)" type="button" value="Press to copy the highlighted text" name="btnCopy">
<p>
<textarea name="select1" rows="4" cols="45"></textarea>
</div>
</form>

<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

danowat
09-04-2003, 04:11 AM
Hi,

In another post, I asked to modify an existing script.

I have doing a bit of surfing, and could I make a script using this command document.execCommand("paste").

All I need to do is paste the text from my clipboard into a textbox, I can't use Ctrl+V, as the application that the html file will run in does not allow keyed commands, so I need a paste button.

Thanks

Dan.

Khalid Ali
09-04-2003, 08:03 AM
You shouldnt have started another thread for this purpose.
Please search the forum,this question has been answered multiple times before.

danowat
09-04-2003, 09:25 AM
Hi,

Sorry for posting twice :( , I am in need of this function, I have searched the forum and I have searched the internet, but all I can find is scripting for the opposite way, I.E copying TO the clipboard, rather than from.

I need a button to paste the contents of the clipboard into a text window.

Sorry again for the multiple post, but I really need this function.

Thank you

Dan.

danowat
09-04-2003, 03:30 PM
Hi,

I have managed to cobble together a script that works to paste the clipboard text.

Now I need to save the whole file using a button, I have created some script to save the page, but the pasted text in the textbox does not save.

Is there anyway I can make the text in the textbox save with the html file?.

I have included the script I am using, any help would be greatly appreciated.

Thanks

Dan.

<HTML>
<HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<SCRIPT language=JavaScript>
<!-- Begin
function pasteit(theField) {
var val=eval("document."+theField)
val.focus()
val.select()
therange=val.createTextRange()
therange.execCommand("Paste")
}
</SCRIPT>
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY onload=isReady=true>
<FORM name=it>
<DIV align=center><INPUT onclick="pasteit('it.select1')" type=button value="Press to Paste From The Clipboard" name=pste>
<P><TEXTAREA name=select1 rows=20 cols=50></TEXTAREA> </P></DIV></FORM>
<SCRIPT language=JavaScript>
var isReady = false;
function doSaveAs(){
if (document.execCommand){
if (isReady){document.execCommand("SaveAs");}
}else{
alert('Feature available only in Internet Exlorer 4.0 and later.');
}
}
</SCRIPT>
<A href="javascript:doSaveAs()">Click Here To Save This Page </A>
</PRE></BODY></HTML>

instantnet
09-03-2004, 01:34 AM
Anyone have one that works for mozilla?

Or to have a prompt asking the user for the contents to be pasted in?