P
P
Partizanin2015-10-31 22:54:29
JavaScript
Partizanin, 2015-10-31 22:54:29

Why doesn't the second copy to clipboard button work?

Why does the second button not work and what needs to be done to solve this problem?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>

    <script type="text/javascript" src="js/zeroClipboard/ZeroClipboard.js"></script>
    <script type="text/javascript" src="js/jquery-1.11.2.js"></script>

</head>
<body>


<input class="clip_button" type="button" value="button1" onclick="onButtonClicked(this)" id="button1">
<input class="clip_button" type="button" value="button2" onclick="onButtonClicked(this)" id="button2">

<input  id="text1" type="text" value="123" title="textField">

<input  id="text2" type="text" value="456" title="textField">

<textarea title="textArea"></textarea>

<script type="text/javascript">
    function onButtonClicked(button){
        var text;

        if(button.id === 'button1'){
            text = $("#text1").val();
        }else{
            text = $("#text2").val();

        }

        var client = new ZeroClipboard( button );

        client.on( 'ready', function(event) {
            console.log( 'movie is loaded' );

            client.on( 'copy', function(event) {
                event.clipboardData.setData('text/plain', text());
            } );

            client.on( 'aftercopy', function(event) {
                console.log('Copied text to clipboard: ' + event.data['text/plain']);
            } );
        } );

        client.on( 'error', function(event) {
            // console.log( 'ZeroClipboard error of type "' + event.name + '": ' + event.message );
            ZeroClipboard.destroy();
        } );
    }
</script>
</body>
</html>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question