...

View Full Version : Multiple text area to clipboard in IE



chrismcl09
06-26-2009, 02:51 PM
Hi there folks. Amateur coder here looking for some help with a personal project. I have a form with multiple text area's, i am looking to take all the text area's and send it to the clipboard. I know i have to use javascript but cannot seem to get multiple text area's selected. Could anyone please help? I have been given the following and told it can be adapted to copy the actual form contents itself but no idea how.



<script type="text/javascript">
function CopyToClipboard()
{
CopiedTxt = document.selection.createRange();
CopiedTxt.execCommand("Copy");
}
</script>

<form name="Form1">

Here is some text you can copy. You can copy text from anywhere on the page, simply select it and press the Copy to clipboard button. Then you can paste it anywhere you want, in Notepad, Visual Studio or in the textarea below.

<br /><br />

<textarea id="txtArea" cols="60" rows="5">You can also copy text from this textarea. Or you can paste the text here, using the Ctrl+V key combination.</textarea>

<br />

<input type="button" onClick="CopyToClipboard()" value="Copy to clipboard" />

</form>


Can anyone help me copy the entire form possibly and not the text area's?

Many thanks

Chris McLauchlan

Philip M
06-26-2009, 04:59 PM
Your script will work only in IE. And it will only work once, as the IE clipboard does not hold multiple clips. The only way to copy multiple form fields or text areas to the clipboard is to combine them all into a hidden field and then use a button to send the combined content to the clipboard.


<textarea id = "copytext1" rows = 5 cols = "20"></textarea>

<textarea id = "copytext2" rows = 5 cols = "20"></textarea>

<textarea id = "copytext3" rows = 5 cols = "20"></textarea>

<textarea id="holdtext" style ="display:none;"></textarea>
<br><br>
<input type = "button" onClick="ClipBoard();" value = "Copy to Clipboard"</button>

<script type = "text/javascript">

function ClipBoard() {
holdtext.innerText = copytext1.innerText + " " + copytext2.innerText + " " + copytext3.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("RemoveFormat");
Copied.execCommand("Copy");
window.status="Contents copied to clipboard"
setTimeout("window.status=''",2500)
}

</script>


But once again, it will only work in IE.


Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose.


"Insanity is doing the same thing over and over again, but expecting different results." - Rita Mae Brown

chrismcl09
06-26-2009, 09:47 PM
Philip,

You do not know how releived i am that you come up with a solution. It works perfectly. And no form needed either. All can be manipulated with CSS/HTML. I have changed the topic name to suit as per the rules. My appologies about that. I did not read that first. Please do accept my appologies. I think i will be back to this forum when i need help in the future.

Can i just ask quickly, this will work if i name a select query like this wont it?


<select Name="test">
<option value="test">Test</option>
</select>

Chris

Philip M
06-27-2009, 08:32 AM
Can i just ask quickly, this will work if i name a select query like this wont it?


<select Name="test">
<option value="test">Test</option>
</select>



Well, why not try it and find out?

"name" should be so spelled, lower case.

If you are thinking of trying to capture a select box value in the copy-contents-of-form-to-clipboard, that will not work as it stands. Here is the way to do that:-



<select id = "sel">
<option value = "None" selected>Select A Fruit><option>
<option value = "Apple">Apple</option>
<option value = "Orange">Orange</option>
<option value = "Peach" >Peach</option>
</select>

<textarea id = "copytext1" rows = 5 cols = "20"></textarea>

<textarea id = "copytext2" rows = 5 cols = "20"></textarea>

<textarea id = "copytext3" rows = 5 cols = "20"></textarea>

<textarea id="holdtext" style ="display:none;"></textarea>
<br><br>
<input type = "button" onClick="ClipBoard();" value = "Copy to Clipboard"</button>

<script type = "text/javascript">

function ClipBoard() {
var val = document.getElementById("sel").value;
holdtext.innerText = copytext1.innerText + " " + copytext2.innerText + " " + copytext3.innerText + " Option Value " + val;
Copied = holdtext.createTextRange();
Copied.execCommand("RemoveFormat");
Copied.execCommand("Copy");
window.status="Contents copied to clipboard"
setTimeout("window.status=''",2500)
}

</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum