1

hello everyone i am trying to copy the textbox value using jquery but i dont want to use add on plugins Here is my code

 <div class="form-group col-lg-4 col-md-4 col-sm-12 col-xs-12"> 
  <input type="text" id="visor_node_token" name="view" value="Hello World">
 </div>
 <input type="button" name="view" value="Copy" class="btn btn-primary" onclick="copy_node_token()" />
function copy_node_token()
{
  var node = $("#visor_node_token").val();
  $(node).select();
  document.execCommand("Copy");
}`

I am unable to copy the text value.please help me with this

sahana
  • 21
  • 1
  • 2
  • 4
  • refer [THIS](https://stackoverflow.com/a/22581382/3682162) or you can use [_this plugin_](http://code.google.com/p/liveclipboard-jquery/) – Vikrant Dec 19 '17 at 12:01

1 Answers1

1

 <!DOCTYPE html>

  <style>
    #t {
      width: 1px
      height: 1px
      border: none
    }
    #t:focus {
      outline: none
    }
  </style>

  <script>
    function copy(text) {
      var t = document.getElementById('t')
      t.innerHTML = text
      t.select()
      try {
        var successful = document.execCommand('copy')
        var msg = successful ? 'successfully' : 'unsuccessfully'
        console.log('text coppied ' + msg)
      } catch (err) {
        console.log('Unable to copy text')
      }
      t.innerHTML = ''
    }
  </script>

  <textarea id=t></textarea>

  <button onclick="copy('hello world')">
    Click me
  </button>
Rony Patel
  • 357
  • 1
  • 2
  • 14
  • From following link https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript – Rony Patel Dec 19 '17 at 12:06
  • Add the information in your answer. Also, plagiarism is frowned upon here. –  Dec 19 '17 at 12:06