Streaming live at 10am (PST)

Adding input fields dynamically in collection items

Hi guys, I’m having trouble writing a script that adds input fields to a collection item. The concept is that you click a button inside the collection item in order to add an input field to that collection item.

The problem sits in the fact that the buttons in different collection items add input fields to just one collection item, and not the collection item they belong to. Does anyone know why this is? I’m thinking it has something to do with uniqueness.

An example of a script that I wrote:

function add_fields() {
  var dummy = '<input type="text-field" class="text-field" value="1" name="test"/>';
  document.getElementById('destination').innerHTML += dummy;   
}

The script adds an input field to the collection item. But this only works for the first collection item. The buttons in the other collection items are adding input fields to the first one. Why does the code not stay within the collection item? Do I need to specify something else?