Hola
Prueba con esto
Código javascript
:
Ver original<html>
<head>
<title>Crear filas</title>
<script type="text/javascript">
var indiceFila = 0;
function NuevaFila() {
myNewRow = document.getElementById("tabla").insertRow(-1);
if (indiceFila == 1) {
myNewCell=myNewRow.insertCell(-1);
myNewCell.colSpan="4";
var elemento = document.createElement("INPUT");
elemento.setAttribute("type","text");
elemento.setAttribute("size","8");
elemento.setAttribute("maxlength","15");
elemento.setAttribute("name","codigo_" + indiceFila);
elemento.setAttribute("id","codigo_" + indiceFila);
myNewCell.appendChild(elemento);
}else {
myNewCell=myNewRow.insertCell(-1);
var elemento = document.createElement("INPUT");
elemento.setAttribute("type","text");
elemento.setAttribute("size","8");
elemento.setAttribute("maxlength","15");
elemento.setAttribute("name","codigo_" + indiceFila);
elemento.setAttribute("id","codigo_" + indiceFila);
myNewCell.appendChild(elemento);
myNewCell=myNewRow.insertCell(-1);
var elemento2 = document.createElement("INPUT");
elemento2.setAttribute("type","text");
elemento2.setAttribute("size","25");
elemento2.setAttribute("maxlength","40");
elemento2.setAttribute("name","nombre_" + indiceFila);
elemento2.setAttribute("id","nombre_" + indiceFila);
myNewCell.appendChild(elemento2);
myNewCell=myNewRow.insertCell(-1);
var elemento3 = document.createElement("INPUT");
elemento3.setAttribute("type","text");
elemento3.setAttribute("size","10");
elemento3.setAttribute("maxlength","20");
elemento3.setAttribute("name","unidad_" + indiceFila);
elemento3.setAttribute("id","unidad_" + indiceFila);
myNewCell.appendChild(elemento3);
myNewCell=myNewRow.insertCell(-1);
var elemento4 = document.createElement("INPUT");
elemento4.setAttribute("type","text");
elemento4.setAttribute("size","10");
elemento4.setAttribute("maxlength","20");
elemento4.setAttribute("name","cantidad_" + indiceFila);
elemento4.setAttribute("id","cantidad_" + indiceFila);
myNewCell.appendChild(elemento4);
}
indiceFila++;
}
</script>
</head>
<body>
<a href="javascript:void(0);" onClick="NuevaFila()">Adicionar Fila</a>
<br />
<table border="1px" id="tabla">
<tr>
<td>CÓDIGO</td><td>NOMBRE</td><td>UNIDAD</td><td>CANTIDAD</td>
</tr>
</table>
</body>
Suerte