Solved

Dynamically inserted rows not being submitted with form

Posted on 2011-02-16
1
350 Views
Last Modified: 2012-05-11
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
Comment
Question by:saturation
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 34911739
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question