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?
Below piece of code adds texbox dynmically
HTML Part:
<input type="checkbox" name="bugs" value="1">Check this if bugs are not available </br> </br>
<INPUT type="button" value="Add Row" onclick="addBugRow('bugTable')" />
<INPUT type="button" value="Delete Row" onclick="deleteBugRow('bugTable')" />
<TABLE id="bugTable" width="350px" border="1">
<TR>
<TD></TD>
<TD> No. </TD>
<TD> PCR </TD>
<TD> Description </TD>
</TR>
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD> 1 </TD>
<TD> <INPUT type="text" name="pcr[]" size="6"/> </TD>
<TD><textarea cols="75" rows="5" name="bugdata[]"> </textarea> </TD>
</TR>
</TABLE>
Java Script Part
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);
}
on PHP side, I need to get values of the number of textboxes added and their values.
PHP Part:
foreach($_POST['pcr'] as $key=>$value)
echo $key.' '.$value;