title: Greasemonkey\JavaScript Copy to Clipboard button
body: <p>I am trying to write a JavaScript script to add to greasemonkey that adds a button after an element. The onClick for this button should copy the parents element text to the keyboard. I have seen plenty of examples that copy already selected text to the clipboard such as this:</p>
  
  <pre><code>    &lt;SCRIPT LANGUAGE="JavaScript"&gt;
      &lt;!-- Begin
      function copyit(theField) {
      var selectedText = document.selection;
      if (selectedText.type == 'Text') {
      var newRange = selectedText.createRange();
      theField.focus();
      theField.value = newRange.text;
      } else {
      alert('Alert: Select The text in the textarea then click on this button');
      }
      }
      // End --&gt;
      &lt;/script&gt;
      &lt;input onclick="copyit(this.form.text_select)" type="button" value="Click Here to Copy the Highlighted Text" name="copy_button"&gt;
  </code></pre>
  
  <p>Found <a href="http://www.wallpaperama.com/forums/javascript-copy-selected-text-box-select-all-highlight-text-form-copy-paste-t706.html" rel="noreferrer">here</a>. </p>
  
  <p>I have also found that you can select text in input elements.  I have tried combining both techniques, as well as many others with no viable solution yet. I am not even sure why the code above copies to the clipboard. Does anyone have a solution to this? </p>