title: Adding a hidden form field to a dynamically generated Squarespace newsletter block using JS
body: <p>I'm trying to add a hidden field to my homepage newsletter signup at <a href="http://greig.cc/" rel="nofollow">http://greig.cc/</a> so that I can track the signup source in Mailchimp.</p>
  
  <p>This is the code that I'm injecting into the page, but it throws an 'Uncaught TypeError: undefined is not a function' error and I can't work out why.</p>
  
  <p>Is it something to do with the fact that the rest of the form is rendered after the page is loaded? (this is why I'm using the class name to target the form).</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var formcontainer = document.getElementsByClassName('newsletter-form');
  var input = document.createElement('input');
  input.type = 'hidden';
  input.name = 'SOURCE';
  input.id = 'SOURCE';
  input.value = 'homepage';
  formcontainer.appendChild(input);
  &lt;/script&gt;
  </code></pre>
  
  <p>Thanks for reading :)</p>