title: How to get values for dynamically added text boxes in Java Script and PHP
body: <p>I am trying to POST the values of the dynamically added text boxes.
  How to assign names to these new textboxes[as array]?
  How to pass these array values to the .php file?</p>
  
  <p>Below piece of code adds texbox dynmically</p>
  
  <p>HTML Part:</p>
  
  <pre><code>&lt;input type="checkbox" name="bugs" value="1"&gt;Check this if bugs are not available &lt;/br&gt; &lt;/br&gt;
  &lt;INPUT type="button" value="Add Row" onclick="addBugRow('bugTable')" /&gt;
  &lt;INPUT type="button" value="Delete Row" onclick="deleteBugRow('bugTable')" /&gt;
  
  &lt;TABLE id="bugTable" width="350px" border="1"&gt;
  &lt;TR&gt;
              &lt;TD&gt;&lt;/TD&gt;
              &lt;TD&gt; No. &lt;/TD&gt;
              &lt;TD&gt; PCR &lt;/TD&gt; 
          &lt;TD&gt; Description &lt;/TD&gt;
  
  &lt;/TR&gt;
  &lt;TR&gt;
              &lt;TD&gt;&lt;INPUT type="checkbox" name="chk"/&gt;&lt;/TD&gt;
              &lt;TD&gt; 1 &lt;/TD&gt;
              &lt;TD&gt; &lt;INPUT type="text" name="pcr[]" size="6"/&gt; &lt;/TD&gt; 
          &lt;TD&gt;&lt;textarea cols="75" rows="5" name="bugdata[]"&gt; &lt;/textarea&gt; &lt;/TD&gt;
  
  &lt;/TR&gt;
  &lt;/TABLE&gt;
  </code></pre>
  
  <p>Java Script Part</p>
  
  <pre><code>function addBugRow(tableID) {
  
              var table = document.getElementById(tableID);
  
              var rowCount = table.rows.length;
              var row = table.insertRow(rowCount);
  
              var cell1 = row.insertCell(0);
              var element1 = document.createElement("input");
              element1.type = "checkbox";
              cell1.appendChild(element1);
  
              var cell2 = row.insertCell(1);
              cell2.innerHTML = rowCount;
  
              var cell3 = row.insertCell(2);
              var element2 = document.createElement("input");
              element2.type = "text";
          element2.name = "pcr[]"; // text field names in array
          element2.size = 6;
              cell3.appendChild(element2);
  
          }
  </code></pre>
  
  <p>on PHP side, I need to get values of the number of textboxes added and their values.</p>
  
  <p>PHP Part:</p>
  
  <pre><code>foreach($_POST['pcr'] as $key=&gt;$value)
   echo $key.' '.$value;
  </code></pre>