Solved

Dynamically inserted rows not being submitted with form

Posted on 2011-02-16
1
347 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now