4 Replies Latest reply on Jun 1, 2017 6:59 AM by Arlen Walker

    Interesting side-effect with multiple forms on a page

    Arlen Walker

      Note this is present whether you are placing multiple copies of the same form, or just two completely different forms that happen to collect some of the same data (for example, "First Name") on a web page.


      If you try directly walking from a label to its associated input field, it'll fail. For example, let's say the label is in javascript variable 'fieldLabel' and so this javascript:




      is supposed to take you to the control indicated in the label's "for" attribute (useful if you want to tweak a form field based on characteristics of its label). Unfortunately, Marketo gives multiple instances of the same field name the same Name/ID while the browser is expecting ID's to be unique, so that method will retrieve the correct input field only accidentally. It will always return the first matching input field, even if the label you started from is inside a completely different form on the page.


      Just wanted to save someone else time tearing their hair out over why their javascript wasn't working. Took me a while to realize the first form's fields were the ones changing in reaction to the characterstics in the second form's labels.