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
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)"> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.