...

View Full Version : how would i highlight and copy a textarea?



dmsuperman
08-11-2004, 09:25 PM
i want a function to copy a textarea named affiliate, so when i click a button it is highlighted and copied to the clipboard, how would i go about doing this?

basically, this is what i want to happen:

<A href="javascript:HighlightAffiliate()">
<img src="http://img.photobucket.com/albums/v257/sucramreverse/minibanner.gif" border="0"></A>
<BR>
<TEXTAREA name=Affiliate rows=1 cols=1 style="filter: alpha(opacity=0);><a href="http://pixelgrafx.proboards33.com">
<img src="http://img78.photobucket.com/albums/v257/sucramreverse/minibanner.gif">
</a>
</textarea>

basically, I would like to know what to use for the function HighlightAffiliate(), I don't really know it and im new to JS

Basscyst
08-11-2004, 09:41 PM
IE Only:

http://www.htmlgoodies.com/beyond/clipboard.html

Basscsyt

dmsuperman
08-11-2004, 09:48 PM
ty alot, i knew it was simple just didnt know what it was

dmsuperman
08-11-2004, 09:56 PM
ok, this is the entire code, i dont know why its not working:

<script language="JavaScript">
<--
function ClipBoard()
{
holdtext.innerText = copytext.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");
alert("Affiliate code copied!");
}

//-->
</script>
<div align=center><br><BR>
<SPAN ID="copytext" STYLE="display:none;">
<a href="http://pixelgrafx.proboards33.com">
<img src="http://img78.photobucket.com/albums/v257/sucramreverse/minibanner.gif">
</a>
</SPAN>
<TEXTAREA ID="holdtext" STYLE="display:none;">
</TEXTAREA>
<A href="javascript:ClipBoard();">
<img src="http://img.photobucket.com/albums/v257/sucramreverse/minibanner.gif" border="0"></A>
<BR>
</div>
what did i do wrong?

Willy Duitt
08-11-2004, 10:12 PM
Not only is that IE only but many of the recent Critical Updates have disabled Allow paste operations via script....

Check Tools --> Internet Options --> Security --> Custom Level to see if this option has been disabled on your machine. Even if it is not, don't expect that it will not be disabled on any other machine since the recent release of SP2 also disables this option by default....

.....Willy

Basscyst
08-11-2004, 10:14 PM
Here ya go,



<html>
<head>
<script language="JavaScript">
function ClipBoard()
{
holdtext.innerText = copytext.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");
alert("Affiliate code copied!");
}
</script>
</head>
<body>
<div align=center><br><BR>
<SPAN ID="copytext" STYLE="display:inline;">
This is the text to be copied.
</SPAN>
<br>
<TEXTAREA ID="holdtext" STYLE="display:none;">
</TEXTAREA>
<A href="javascript:ClipBoard();">
Click here to copy text above.</A>
<BR>
</div>
</body>
</html>


Basscyst

dmsuperman
08-11-2004, 10:43 PM
i dunno whats up
i know i can copy to clipboard from another cuz it works other places
anyway, i wonder if there is anyway so i dont have textareas cuz i just have some certain text that i dont want them to see but i want it to be copied to the clipboard when they hit a button, if this makes it easier
i have some code that i want to be copied to the clipboard when they click the link
is there anyway to do it like this:
<script>
function Highlight(){
copy = "<a href="http://pixelgrafx.proboards33.com">
<img src="http://img78.photobucket.com/albums/v257/sucramreverse/minibanner.gif" border=0>
</a>"
alert("Code copied!");
}
</script>
<a href="javascript:Highlight();">Click to copy code</a>
if this would make it easier that would be good, but the other one doesnt work for some reason

dmsuperman
08-12-2004, 02:27 AM
could someone help me out?

Willy Duitt
08-12-2004, 07:30 AM
I've already explained that this is a security threat which Mozilla addressed long ago and thankfully Microsoft is finally getting around to fixing. Thus, what you are trying to do is an exercise in futility. Even it you get it to work on your machine, it will not work on the majority of other machines. And even if it works on another machine today, it will not work once they become updated with SP2...

Quit trying to hide the text you want the user to copy and display this text in a textarea using the READONLY attribute to prevent them from editting the content....

......Willy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum