title: add/remove dynamic textboxes uniquely using javascript or appscript
body: <p>I got this code from <a href="https://stackoverflow.com/questions/39283622/dynamically-adding-text-boxes-in-html-using-javascript-syntax-error-occurs">here</a> which i have modified a bit to add unique numbers to the inputs.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var i = 1;
  
  function addkid() {
    i++;
    var div = document.createElement('div');
    var id = i;
    div.innerHTML = 'Child_' + id + ': &lt;input type="text" name="child_' + id + '"/&gt;' + ' &lt;input type="button" id="add_kid()_' + id + '" onclick="addkid()" value="+" /&gt;' + ' &lt;input type="button" id="rem_kid()_' + id + '" onclick="remkid(this)" value="-" /&gt;';
    document.getElementById('kids').appendChild(div);
  }
  
  function remkid(div) {
    document.getElementById('kids').removeChild(div.parentNode);
    i--;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form&gt;
    Name:
    &lt;input type="text" name="name"&gt;
    &lt;br/&gt;
    &lt;div id="kids"&gt;
      Child_1:
      &lt;input type="text" name="child_1"&gt;
      &lt;input type="button" id="add_kid()_1" onclick="addkid()" value="+" /&gt;
    &lt;/div&gt;
    Phone:
    &lt;input type="text" name="phone"&gt;
    &lt;br/&gt;
    &lt;input type="submit" name="submit" value="submit" /&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>When i view it in the browser, i can add/remove textboxes properly, but if i remove some textboxes from in-between, then the Child_id numbers repeat again, resulting in input textboxes with duplicate IDs.</p>
  
  <ol>
  <li>How do i make sure there are no duplicate or missing ids?</li>
  <li>How can i grab values from each of these dynamic textboxes using their IDs or name and create a JSON object dynamically on submit?</li>
  <li>How can i pass on these values or the JSON object to Appscript?</li>
  </ol>
  
  <p>Any help would be most welcome.</p>