Solved

Dynamically inserted rows not being submitted with form

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
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…

809 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