title: Set input value with text in link with javascript
body: <p>I have an input field <code>&lt;input type=&quot;text&quot; name=&quot;input&quot;&gt;</code>.</p>
  <p>I also have some links:</p>
  <pre><code>&lt;div&gt;
  &lt;a href=&quot;#&quot;&gt;first link&lt;/a&gt;
  &lt;a href=&quot;#&quot;&gt;second link&lt;/a&gt;
  ...
  &lt;/div&gt;
  </code></pre>
  <p>I want to let the user click on a link and set the value of the input with the value in the link.</p>
  <p>I guess I should do something like:</p>
  <pre><code>const input = document.getElementById('input');
  
  document.getElementsByTagName('a').forEach(function () {
    this.onclick = function () {
      input.value = this.innerHTML();
    }
  });
  </code></pre>
  <p>but I know that <code>document.getElementsByTagName('a')</code> doesn't return an array, so it's not possible, and I am not sure if this is the right approach.</p>