Solved

Dynamically inserted rows not being submitted with form

Posted on 2011-02-16
1
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

687 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