• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

Dynamically inserted rows not being submitted with form

My code below, when the form is submitted (there is a submit button not currently in this code), does not submit any of the dynamically added rows.   It actually only even submits the first checkbox.  How can I get it to save dynamically added rows?
<HEAD>
       <SCRIPT language="javascript">

       	function addRow(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);
       		cell1.className = "VIEWBOXCAPTION";

       		var cell2 = row.insertCell(1);
       		cell2.innerHTML = rowCount + 1;
       		cell2.className = "VIEWBOXCAPTION";

       		var cell3 = row.insertCell(2);
       		var element2 = document.createElement("input");
       		cell3.className = "VIEWBOXCAPTION";

       		element2.type = "text";
       		element2.size = 150;
       		cell3.appendChild(element2);

       	}

       	function deleteRow(tableID) {
       		try {
       			var table = document.getElementById(tableID);
       			var rowCount = table.rows.length;

       			for (var i=0; i<rowCount; i++) {
       				var row = table.rows[i];
       				var chkbox = row.cells[0].childNodes[0];

       				if (null != chkbox && true == chkbox.checked) {
       					table.deleteRow(i);
       					rowCount--;
       					i--;
       				}
       			}
       		} catch(e) {
       			alert(e);
       		}
       	}
       </SCRIPT>

</HEAD>


<BODY>
<form name="Deliverables" METHOD=POST action='SaveDeliverables.asp'>
	<INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />

	<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />

	<TABLE id="dataTable" width="350px" border="1">
		<TR>
			<TD><INPUT type="checkbox" name="chk"/></TD>
			<TD> 1 </TD>
			<TD> <INPUT type="text" /> </TD>
		</TR>
	</TABLE>
</form>
</BODY>

Open in new window

0
saturation
Asked:
saturation
1 Solution
 
leakim971PluritechnicianCommented:
By rows I understand the input elements : You MUST add a name for your INPUT elements, for example :

var element1 = document.createElement("input");
element1.type = "checkbox";
element1.name = "checkbox" + counter;
counter++;

Open in new window

0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now