Wednesday, 15 January 2014

javascript - Adding a hidden form field to a dynamically generated Squarespace newsletter block using JS -


I am trying to add a hidden field to my homepage newsletter signup so that I can track the signup source in Mailchimp Can I

This is the code, which I am injected in the page, but it throws an 'Uncort Type Error: Undefined No Function' error and why I can not work.

> Is there anything with this fact that the rest of the form is provided after the page is loaded? (That's why I'm using class names to target the form).

  & lt; Script type = "text / javascript" & gt; Var form container = 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;  

Thanks for reading :)

In two things My Fixed :)

(1) Waiting for the DOM to load before the script is running (2) getElementsByClassName to get the first item in the array to shuffle through. {This is not bothering the loop through this because I only have 1 form per page)

   

No comments:

Post a Comment