title: Javascript function: how to reference the element that calls the function - and extract that element's value
body: <p>I am trying to make a table with a button for each row, each button I want to have it copy and paste the value of the button itself to the desired field.
  my problem is I don't get texttocopy to be the <code>&lt;input button value=""&gt;</code> </p>
  
  <pre><code>copypaste(id) {
     var texttocopy = document.getElementById(this);
     var wheretocopy = document.getElementById(id);
     wheretocopy.value = texttocopy.value;
  }
  </code></pre>
  
  <p>I've tried a few other variations on this, and looking up the syntax has been unfruitful.</p>
  
  <pre><code>function copypaste(id) {
     var texttocopy = this;
     var wheretocopy = document.getElementById(id);
     wheretocopy.value = texttocopy.value;
  }
  </code></pre>
  
  <p><code>texttocopy</code> is the value of whatever calls the function.</p>
  
  <p>the html is inside php so that's the reason for the . connectors and the switching of " and '.</p>
  
  <p>where the button is:
      <code>php
      echo '&lt;input TYPE="BUTTON" id="barcodebutton" value ="'.$row['barcode1'].'" onclick="copypaste('."'primaryRFID'".');"&gt;'
  </code></p>
  
  <p>field to input data into:
      <code>html
      &lt;INPUT TYPE="TEXT" id="primaryRFID" NAME="primaryRFID"&gt;
  </code></p>
  
  <p>the expected result is the input of primaryRFID becomes the value of the button pressed.</p>