JavaScript - Remove row

 
Vista:

Remove row

Publicado por Dani (2 intervenciones) el 06/10/2007 16:36:15
Hola

Tengo el siguiente codigo y a la hora de borrar la fila me da un error,
tanto en el explorer como en el firefox, en el firefox me dice que no encuentra el nodo Node was not found" code: "8

Alguien me puede ayudar a corregir el codigo de la funcion removeRow ahi es donde esta mal no se solucionarlo, la funcion addRow funciona bien la he copiado por internet :-)

Muchas gracias es muy urgente!!


<html>
<head>
<script language="JavaScript">

idFila = 1;

function addRow(nombreTabla){
idFila++; //id de la fila

var tbody = document.getElementById
(nombreTabla).getElementsByTagName("TBODY")[0];

//Primera fila
var row = document.createElement("TR")
row.id = idFila;

//Con 4 columnas
var td1 = document.createElement("TD")
var td2 = document.createElement("TD")
var td3 = document.createElement("TD")
var td4 = document.createElement("TD")

row.appendChild(td1).innerHTML="<input type=text name=fila"+idFila+"columna1>";
row.appendChild(td2).innerHTML="<input type=text name=fila"+idFila+"columna2>"
row.appendChild(td3).innerHTML='<input type=button value="+" onclick=javascript:addRow("tabla1");>';
row.appendChild(td4).innerHTML='<input type=button value="-" onclick=javascript:removeRow("tabla1",'+idFila+');>';
tbody.appendChild(row);
}

function removeRow(nombreTabla, filaAborrar) {
var d = document.getElementById(nombreTabla);
d.removeChild(document.getElementById(filaAborrar));
}
</script>
</head>

<body>

<table id="tabla1" cellspacing="0" border="1" width="100%">
<tbody>
<tr id="0">
<td>COLUMNA 1</td>
<td>COLUMNA 2</td>
<td> </td>
<td> </td>
</tr>
<tr id="1">
<td><input type="text" name="fila1columna1"></td>
<td><input type="text" name="fila1columna2"></td>
<td><input type="button" value="+" onclick="javascript:addRow('tabla1');" alt="Añadir fila"></td>
<td><input type="button" value="-" onclick="javascript:removeRow('tabla1','1');" alt="Borrar fila"></td>
</tr>
</tbody>
</table>

</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Remove row

Publicado por zenhaust (4 intervenciones) el 12/10/2007 12:30:59
Estas intentando borrar una fila que pende de un tbody, NO de una tabla.
Deberías hacer

var d = document.getElementById(nombreTabla).firstChild;
d.removeChild(document.getElementById(filaAborrar));

donde firstChild es el primer hijo de la tabla, es decir el tbody.

http://jsblock.ath.cx/cry
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Remove row

Publicado por Andrea (3 intervenciones) el 27/10/2007 18:31:41
Cuando le doy borrar una fila... no funciona.. de hecho mi firebug dice que el nodo no fue encontrado...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar