All pastes #2050889 Raw Edit

Mine

public text v1 · immutable
#2050889 ·published 2011-04-26 14:57 UTC
rendered paste body
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Example</title>
		
		<script>
			var c = 0;
			
			function removeLine(q)
			{
				table = document.getElementById('db');
				tr = document.getElementById('data' + q);
				
				table.tBodies[0].removeChild(tr);
				
				return false;
			}
			
			function addLine()
			{
				c++;
				table = document.getElementById('db');
			
				/* creating tr */
				newRow = document.createElement("tr");
				newRow.id = 'data' + c;
				
				/* creating td with input for name */
				newColumnName = document.createElement("td");
				
				/* creating input */
				newNameField = document.createElement("input");
				newNameField.name = 'name[' + c +']';
				
				/* append input to td */
				newColumnName.appendChild(newNameField);
				
				/* append td with input to tr */
				newRow.appendChild(newColumnName);
				
				/* creating td with input for date */
				newColumnDate = document.createElement("td");
				
				/* creating input */
				newDateField = document.createElement("input");
				newDateField.name = 'date[' + c +']';
				
				/* append input to td */
				newColumnDate.appendChild(newDateField);
				
				/* append td with input to tr */
				newRow.appendChild(newColumnDate);
				
				/* creating td with link */
				newColumnLink = document.createElement("td");
				
				/* creating link */
				deleteLink = document.createElement("a");
				deleteLink.innerHTML = "delete";
				deleteLink.href = "#";
				deleteLink.num = c;
				deleteLink.onclick = function(){
					return removeLine(this.num);
				}
				
				/* append link to td */
				newColumnLink.appendChild(deleteLink);

				/* append td with link to tr */
				newRow.appendChild(newColumnLink);
				
				/* append tr to table */
				table.tBodies[0].appendChild(newRow);

				return false;
			}
		</script>
	</head>
	<body>
		<table border="0" cellspacing="0" cellpadding="3" id="db">
			<caption>Сведения о детях</caption>
			<tr>
				<td>Name</td>
				<td>Date of birth</td>
				<td>
					<a href="#" onclick="return addLine();">add</a>
				</td>
			</tr>
			
			<tr id="data0">
				<td>
					<input type="text" name="name[0]" />
				</td>
				<td>
					<input type="text" name="date[0]" />
				</td>
				<td>
					<a href="#" onclick="return removeLine(0);">delete</a>
				</td>
			</tr>			
		</table>
	</body>
</html>