Use Javascript to copy Text from Label

Posted by Josh on Stack Overflow See other posts from Stack Overflow or by Josh
Published on 2010-05-06T21:23:20Z Indexed on 2010/05/07 16:08 UTC
Read the original article Hit count: 410

Filed under:
|

Hello All-

Label1 (asp.net control) is located inside Panel1 of my webpage and I have a button called bt. What is the Javascript to copy the Text from Label1 to the clipboard?

Thanks,

@ artlung, I placed the below code just outside of my form but inside the body. The last line of code I placed inside Panel1 of my form. Anything wrong with this code because nothing happens when I click the Copy to Clipboard button.

<script language="JavaScript"> 
                    var clip = new ZeroClipboard.Client(); 
                    clip.addEventListener( 'mouseDown', function(client) {  
                            // set text to copy here 
                            clip.setText( document.getElementById('form1.Label1').value ); 

                            // alert("mouse down");  
                    } ); 

                    clip.glue( 'd_clip_button' ); 
            </script> 

The next line of code is above the script tags but inside Panel1 in my form

<div id="d_clip_button">Copy To Clipboard</div>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about ASP.NET