title: Generate arrays using dynamically generated forms
body: <p>Basically, I'm using JavaScript to dynamically generate a form that allows from multiple entries within a single submission.  Here's the code I'm using for that:</p>
  
  <pre><code>function addEvent()
  {
   var ni = document.getElementById('myDiv');
   var numi = document.getElementById('theValue');
   var num = (document.getElementById('theValue').value - 1) + 2;
   numi.value = num;
   var divIdName = 'my' + num + 'Div';
   var newdiv = document.createElement('div');
   newdiv.setAttribute('id', divIdName);
   newdiv.innerHTML = '&lt;table id="style" style="background-color: #ffffff;"&gt;&lt;tr&gt;&lt;td colspan="2"&gt;Entry ' + num + '&lt;hr \/&gt;&lt;\/td&gt;&lt;\/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;label&gt;Item 1: &lt;\/td&gt;&lt;td&gt;&lt;input name="item1_' + num + '" value="" type="text" id="item1" \/&gt;&lt;\/label&gt;&lt;\/td&gt;&lt;\/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;label&gt;Item 2: &lt;\/td&gt;&lt;td&gt;&lt;input name="item2_' + num + '" type="text" id="item2" \/&gt;&lt;\/label&gt;&lt;\/td&gt;&lt;\/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;label&gt;Item 3: &lt;\/td&gt;&lt;td&gt;&lt;input type="text" name="item3_' + num + '" id="item3" \/&gt;&lt;\/label&gt;&lt;\/td&gt;&lt;\/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;label&gt;Item 4: &lt;\/td&gt;&lt;td&gt;&lt;select name="item4_' + num + '" id="item4"&gt;&lt;option value="---"&gt;---&lt;\/option&gt;&lt;option value="opt_1"&gt;1&lt;\/option&gt;&lt;option value="opt_2"&gt;2&lt;\/option&gt;&lt;option value="opt_3"&gt;3&lt;\/option&gt;&lt;option value="opt_4"&gt;4&lt;\/option&gt;&lt;\/select&gt;&lt;\/label&gt;&lt;\/td&gt;&lt;\/tr&gt;&lt;\/table&gt;';
   ni.appendChild(newdiv);
  }
  </code></pre>
  
  <p>This works just fine, generating the entries fields I need.  Using console in-browser, I've even verified all the names are correct.  The issue is that I need to then take the selections and generate output.  I've tried several methods, but everything resulted in null values.</p>
  
  <pre><code>function generateVideo()
  {
   var entries = document.getElementById('theValue').value;
   var item1 = {};
   var item2 = {};
   var item3 = {};
   var item4 = {};
   for(i = 1; i &lt;= entries; i++)
   {
    item1[i - 1] = document.getElementById('item1_' + i);
    item2[i - 1] = document.getElementById('item2_' + i);
    item3[i - 1] = document.getElementById('item3_' + i);
    item4[i - 1] = document.getElementById('item4_' + i);
   }
   var code = 'Copy code and paste it into Notepad&lt;br \/&gt;"Save as" filename.html&lt;br \/&gt;&lt;textarea name="" cols="45" rows="34"&gt;header template\n';
   for(i = 0; i &lt; entries; i++)
   {
    if(i != (entries - 1))
    {
     code = code + '     ["' + item1[i] + '", "' + item2[i] + '", "' + item3[i] + '", "' + item4[i] + '"],\n';
    }
    else
    {
     code = code + '     ["' + item1[i] + '", "' + item2[i] + '", "' + item3[i] + '", "' + item4[i] + '"]\n';
    }
   }
   code = code + 'footer template&lt;\/textarea&gt;';
   var result = document.getElementById("result");
   result.innerHTML = code;
  }
  </code></pre>
  
  <p>The output is as follows:</p>
  
  <pre><code>Copy code and paste it into Notepad&lt;br /&gt;"Save as" CourseName_Unit_Chapter.html&lt;br /&gt;&lt;textarea name="" cols="45" rows="34"&gt;header template
       ["null", "null", "null", "null"]
  footer template&lt;/textarea&gt;
  </code></pre>
  
  <p>Now, certain fields can be null, that's fine (I'll do form validation after I get it working), but I'm getting null for every field regardless of what is entered.</p>
  
  <p>I, originally, had the .value on the getElementByIds, but that only results in the script not running when the entries variable is greater than 0 (default), which is why I tried removing them.</p>
  
  <pre><code>function generateVideo()
  {
   var entries = document.getElementById('theValue').value;
   var item1 = {};
   var item2 = {};
   var item3 = {};
   var item4 = {};
   for(i = 1; i &lt;= entries; i++)
   {
    item1[i - 1] = document.getElementById('item1_' + i).value;
    item2[i - 1] = document.getElementById('item2_' + i).value;
    item3[i - 1] = document.getElementById('item3_' + i).value;
    item4[i - 1] = document.getElementById('item4_' + i).value;
   }
   var code = 'Copy code and paste it into Notepad&lt;br \/&gt;"Save as" filename.html&lt;br \/&gt;&lt;textarea name="" cols="45" rows="34"&gt;header template\n';
   for(i = 0; i &lt; entries; i++)
   {
    if(i != (entries - 1))
    {
     code = code + '     ["' + item1[i] + '", "' + item2[i] + '", "' + item3[i] + '", "' + item4[i] + '"],\n';
    }
    else
    {
     code = code + '     ["' + item1[i] + '", "' + item2[i] + '", "' + item3[i] + '", "' + item4[i] + '"]\n';
    }
   }
   code = code + 'footer template&lt;\/textarea&gt;';
   var result = document.getElementById("result");
   result.innerHTML = code;
  }
  </code></pre>
  
  <p>I've also tried variations of multidimensional arrays, instead of four arrays, but got the same results.</p>
  
  <p>The output, as indicated by the removal of the .value on the getElementByIds, is good.  Basically, there is something wrong with my attempts to populate the arrays using the dynamically generated forms.</p>
  
  <p>I suspect that the issue with the declaration of the element ID, but I'm not sure how else to declare it.  This style of scripting is not my norm. ^^'</p>
  
  <p>Anyone have any ideas on how to fix the for loop to generate the array?</p>