Foros del Web » Programando para Internet » Javascript »

Filas dinamicas

Estas en el tema de Filas dinamicas en el foro de Javascript en Foros del Web. Hola a todos tengo un pequeño problema quiero que al dar clic en el boton agregar fila se vayan creando filas. alguien tiene un codigo ...
  #1 (permalink)  
Antiguo 14/05/2010, 13:41
 
Fecha de Ingreso: mayo-2010
Mensajes: 153
Antigüedad: 14 años
Puntos: 0
Exclamación Filas dinamicas

Hola a todos

tengo un pequeño problema quiero que al dar clic en el boton agregar fila
se vayan creando filas.

alguien tiene un codigo con que me pueda ayudar

Les agradesco de antemano.
  #2 (permalink)  
Antiguo 14/05/2010, 14:09
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Filas dinamicas

Hola

Prueba con este código

Código Javascript:
Ver original
  1. <html>
  2. <head>
  3. <title>Crear filas</title>
  4. <script type="text/javascript">
  5. var indiceFila = 0;
  6. function NuevaFila() {
  7.  
  8.     if (indiceFila <= 5 ) {
  9. myNewRow = document.getElementById("tabla").insertRow(-1);
  10.         myNewCell=myNewRow.insertCell(-1);
  11.         var elemento = document.createElement("INPUT");
  12.         elemento.setAttribute("type","text");
  13.         elemento.setAttribute("size","8");
  14.         elemento.setAttribute("maxlength","15");
  15.         elemento.setAttribute("name","codigo_" + indiceFila);
  16.         elemento.setAttribute("id","codigo_" + indiceFila);
  17.         myNewCell.appendChild(elemento);
  18.  
  19.         myNewCell=myNewRow.insertCell(-1);
  20.         var elemento2 = document.createElement("INPUT");
  21.         elemento2.setAttribute("type","text");
  22.         elemento2.setAttribute("size","25");
  23.         elemento2.setAttribute("maxlength","40");
  24.         elemento2.setAttribute("name","nombre_" + indiceFila);
  25.         elemento2.setAttribute("id","nombre_" + indiceFila);
  26.         myNewCell.appendChild(elemento2);
  27.  
  28.         myNewCell=myNewRow.insertCell(-1);
  29.         var elemento3 = document.createElement("INPUT");
  30.         elemento3.setAttribute("type","text");
  31.         elemento3.setAttribute("size","10");
  32.         elemento3.setAttribute("maxlength","20");
  33.         elemento3.setAttribute("name","unidad_" + indiceFila);
  34.         elemento3.setAttribute("id","unidad_" + indiceFila);
  35.         myNewCell.appendChild(elemento3);
  36.  
  37.         myNewCell=myNewRow.insertCell(-1);
  38.         var elemento4 = document.createElement("INPUT");
  39.         elemento4.setAttribute("type","text");
  40.         elemento4.setAttribute("size","10");
  41.         elemento4.setAttribute("maxlength","20");
  42.         elemento4.setAttribute("name","cantidad_" + indiceFila);
  43.         elemento4.setAttribute("id","cantidad_" + indiceFila);
  44.         myNewCell.appendChild(elemento4);
  45.     }
  46. indiceFila++;
  47. }  
  48. </script>
  49. </head>
  50. <body>
  51. <a href="javascript:void(0);" onClick="NuevaFila()">Adicionar Fila</a>
  52. <br />
  53. <table border="1px" id="tabla">
  54. <tr>
  55. <td>CÓDIGO</td><td>NOMBRE</td><td>UNIDAD</td><td>CANTIDAD</td>
  56. </tr>
  57. <tr id="0"
  58. <td><input type="text" size="8" maxlength="15" name="codigo_0" id="codigo_0" /></td>
  59. <td><input type="text" size="25" maxlength="40" name="nombre_0" id="nombre_0" /></td>
  60. <td><input type="text" size="10" maxlength="20" name="unidad_0" id="unidad_0" /></td>
  61. <td><input type="text" size="10" maxlength="20" name="cantidad_0" id="cantidad_0" /></td>
  62. </tr>
  63. </table>
  64. </body>

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #3 (permalink)  
Antiguo 14/05/2010, 14:14
 
Fecha de Ingreso: mayo-2010
Mensajes: 153
Antigüedad: 14 años
Puntos: 0
Respuesta: Filas dinamicas

Comapañero que pena con vos es que soy nuevo con javascript
y como hiciera para eliminar las filas.
  #4 (permalink)  
Antiguo 14/05/2010, 15:10
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Filas dinamicas

Hola

Cita:
Iniciado por jonnyalex_1990 Ver Mensaje
Comapañero que pena con vos es que soy nuevo con javascript
y como hiciera para eliminar las filas.
Ensayo error, colega. Busca por removeChild

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />

Etiquetas: dinamicas, filas
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:32.