Code:
<!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" />
<LINK rel=stylesheet type=text/css href="main.css">
<title>blah</title>
<script type="text/javascript">
function addRowToTable(){
if(addRowToTable.rowNum >= 15){
return;
}
var tbl = document.getElementById('tblAddress'),
row = tbl.rows[1].cloneNode(true), inputs, i = 0,
character = String.fromCharCode(addRowToTable.charNum + (addRowToTable.rowNum++));
tbl.rows[1].parentNode.appendChild(row);
inputs = row.getElementsByTagName('input');
for(i; i < inputs.length; ++i){
inputs[i].name = inputs[i].name.replace(addRowToTable.re, character);
inputs[i].id = inputs[i].id.replace(addRowToTable.re, character);
}
showRemove();
}
addRowToTable.charNum = 'a'.charCodeAt(0);
addRowToTable.rowNum = 1;
addRowToTable.re = /a$/;
function removeRow(){
var row = document.getElementById('tblAddress').rows;
row = row[row.length - 1];
row.parentNode.removeChild(row);
showRemove();
--addRowToTable.rowNum;
}
function showRemove(){
var removes = document.getElementById('tblAddress').getElementsByTagName('a'), r = removes.length, i = 1;
for(i; i < r; ++i){
removes[i].style.visibility = i === r - 1? 'visible' : 'hidden';
}
}
</script>
</head>
<body>
<form action="blah.php" name="h" method="post">
<table class="tblHeader" id="tblAddress">
<tr>
<td class="txtBase">Dept ID</td>
<td class="txtBase"><p>Acct-Prime<br />
/Sub</p></td>
<td class="txtBase">ExpCode</td>
<td class="txtBase">Prj Code</td>
<td class="txtBase">Loc</td>
<td class="txtBase">Acct</td>
<td class="txtBase"> </td>
</tr>
<tr>
<td><input name="org1a" type="text" size="8" maxlength="8" id="org1a" /></td>
<td><input name="org2a" type="text" size="4" maxlength="4" id="org2a" /></td>
<td><input name="org3a" type="text" size="4" maxlength="4" id="org3a" /></td>
<td><input name="org4a" type="text" size="4" maxlength="4"id="org4a" /></td>
<td><input name="org5a" type="text" size="4" maxlength="4" id="org5a" /></td>
<td><input name="org6a" type="text" size="9" maxlength="9" id="org6a" /></td>
<td><a style="visibility: hidden;" href="#" onclick="removeRow(); return false;">minus-</a></td>
</tr>
</table>
<p>
<a href="#" onClick="addRowToTable(); return false;">add+</a>
</p>
<p><br />
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
Bookmarks