Jump to content

Instant Text copy button


npsari

Recommended Posts

Posted: Wed May 02, 2007 10:19 pm    Post subject: Instant Text copy button 

 

--------------------------------------------------------------------------------

 

The below script allows text copy in a click of a button:

Try it out, it is nice actually

 

<script type="text/javascript"> 
function cmdA(el) { 
with(el){ 
focus(); 
select(); 
} 
if(document.all){ 
txt=el.createTextRange() 
txt.execCommand("Copy") 
window.status='Selected and Copied to Clipboard!' 
document.WordForm.cpyButton.value="Copied!"; 
setTimeout("WordForm.cpyButton.value='Copy'",1000) 
} 
else window.status='Press Ctrl-C to Copy the Text to the Clipboard' 
setTimeout("window.status='WebTv users you must Press Cmd & C !'",3000) 
} 
</script> 


<form name="WordForm" > 
<input type="text" id="Editbox1" size="30" name="Screen" value="Yo wassup dudeee"> <input type="button" width="120" NAME="cpyButton" value="Copy" onClick="cmdA(document.WordForm.Screen)"> 

 

However, when the button is clicked, another button shows with the word copied!

 

Can someone show me how can the script display an image (/images/copied.gif) instead of the button.

 

Your support is appreciated

npsari

 

Link to comment
https://forums.phpfreaks.com/topic/49788-instant-text-copy-button/
Share on other sites

  • 1 year later...

Hey sorry for the late reply but what the hell.

 

 

 

 

Here:

 

<script type="text/javascript"> 
function cmdA(el) { 
with(el){ 
focus(); 
select(); 
} 
if(document.all){ 
txt=el.createTextRange() 
txt.execCommand("Copy") 
window.status='Selected and Copied to Clipboard!' 
<img src="/images/copied.gif" alt="Copied!" />
setTimeout("WordForm.cpyButton.value='Copy'",1000) 
} 
else window.status='Press Ctrl-C to Copy the Text to the Clipboard' 
setTimeout("window.status='WebTv users you must Press Cmd & C !'",3000) 
} 
</script> 


<form name="WordForm" > 
<input type="text" id="Editbox1" size="30" name="Screen" value="Yo wassup dudeee"> <input type="button" width="120" NAME="cpyButton" value="Copy" onClick="cmdA(document.WordForm.Screen)"> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.