Ver Mensaje Individual
  #5 (permalink)  
Antiguo 21/11/2008, 14:35
Avatar de kilpo
kilpo
 
Fecha de Ingreso: noviembre-2008
Mensajes: 19
Antigüedad: 15 años, 5 meses
Puntos: 0
Respuesta: Problema al borrar un fila de una tabla

Cita:
Iniciado por vmac179 Ver Mensaje
no uses InnerHTML, usa DOM, creo que esto te sirve

Código javascript:
Ver original
  1. <style>
  2.  
  3. .tabla
  4. {
  5.  background-color: orange;
  6. }
  7.  
  8. .titulos
  9. {
  10.  text-align: center;
  11.  font-weight: bolder;
  12.  background-color: yellow;
  13. }
  14.  
  15. .fila
  16. {
  17.  background-color: white;
  18. }
  19.  
  20. </style>
  21.  
  22. <script language="javascript">
  23.  
  24. function agregar_fila(origen, destino)
  25. {
  26.     ///////////////////////////////////////////
  27.  
  28.     var nombres   = origen.nombres.value;
  29.     var apellidos = origen.apellidos.value;
  30.  
  31.     var nuevo_indice = destino.rows.length;
  32.  
  33.     var fila;
  34.     var celda;
  35.     var valor;
  36.    
  37.     fila = destino.insertRow(nuevo_indice);
  38.     fila.style.background = "white";
  39.    
  40.     ///////////////////////////////////////////
  41.  
  42.     celda = fila.insertCell(0);
  43.     valor = document.createElement("input");
  44.         valor.type = "checkbox";
  45.         valor.id = "marca";
  46.         valor.name = "marca";
  47.         valor.value = nuevo_indice;
  48.     celda.appendChild(valor);
  49.  
  50.     ///////////////////////////////////////////
  51.  
  52.     celda = fila.insertCell(1);
  53.     valor = document.createTextNode(nombres + " - " + nuevo_indice);
  54.     celda.appendChild(valor);
  55.    
  56.     ///////////////////////////////////////////
  57.  
  58.     celda = fila.insertCell(2);
  59.     valor = document.createTextNode(apellidos);
  60.     celda.appendChild(valor);
  61.  
  62.     ///////////////////////////////////////////
  63. }
  64.  
  65. function remover_filas_marcadas(origen)
  66. {
  67.     ///////////////////////////////////////////
  68.  
  69.     var inputs = origen.getElementsByTagName("input");
  70.     var checkboxes = new Array();
  71.     var chk_cuenta = 0;
  72.    
  73.     ///////////////////////////////////////////
  74.  
  75.     for (i=0; i<inputs.length; i++)
  76.     {
  77.         if (inputs[i].type == "checkbox" &&
  78.             inputs[i].id == "marca" &&
  79.             inputs[i].checked)
  80.         {
  81.             checkboxes[chk_cuenta] = inputs[i];
  82.             chk_cuenta ++;
  83.         }
  84.     }
  85.  
  86.     ///////////////////////////////////////////
  87.  
  88.     for (i=0; i<checkboxes.length; i++)
  89.     {
  90.         origen.deleteRow(checkboxes[i].value - 1*i);
  91.     }  
  92.  
  93.     ///////////////////////////////////////////
  94.    
  95.     corregir_indices_tabla(origen);
  96.  
  97.     ///////////////////////////////////////////
  98. }
  99.  
  100. function corregir_indices_tabla(origen)
  101. {
  102.     ///////////////////////////////////////////
  103.  
  104.     var inputs = origen.getElementsByTagName("input");
  105.    
  106.     ///////////////////////////////////////////
  107.  
  108.     for (i=0; i<inputs.length; i++)
  109.     {
  110.         if (inputs[i].type == "checkbox" &&
  111.             inputs[i].id == "marca")
  112.         {
  113.             inputs[i].value = i + 1;
  114.         }
  115.     }
  116.  
  117.     ///////////////////////////////////////////
  118. }
  119.  
  120. </script>
  121.  
  122. <table class="tabla" id="info" name="info">
  123. <tr class="titulos">
  124.     <td>
  125.         Marca
  126.     </td>
  127.     <td>
  128.         Nombres
  129.     </td>
  130.  
  131.     <td>
  132.         Apellidos
  133.     </td>
  134. </tr>
  135. </table>
  136.  
  137. <br />
  138.  
  139. <form id="datos" name="datos">
  140.   Nombres:   <input type="text" id="nombres" name="nombres" value="" size="25" />
  141.   Apellidos: <input type="text" id="apellidos" name="apellidos" value="" size="25" />
  142.  
  143.   &nbsp;
  144.   <input type="button" id="agregar" name="agregar" value="Agregar" onClick="agregar_fila(datos, info)" />
  145.   <input type="button" id="remover" name="remover" value="Remover" onClick="remover_filas_marcadas(info)" />
  146. </form>
gracias vmac179 pero no logro enterder como crea las tabla la funcion agregar_fila o como podria agegar mas celdas a esta funcion.