Ver Mensaje Individual
  #4 (permalink)  
Antiguo 01/08/2012, 19:42
Avatar de dontexplain
dontexplain
 
Fecha de Ingreso: junio-2012
Mensajes: 536
Antigüedad: 11 años, 11 meses
Puntos: 127
Respuesta: Matrices en tablas dinamicas html con javascript

Es lo que sucede cuando usas indiscriminadamente el document.write sin conocer realmente el DOM y cómo funciona.

Para eso creas una variable que se va rellenando con variable+='nuevo valor' y al final introduces el código con innerHTML

Me tomé la molestia de pasarlo todo nuevamente

Código Javascript:
Ver original
  1. function genMatrices(filA, colA, filB, colB) {
  2.                 c=new String();
  3.                 e=document.getElementById('divMatrices');
  4.                 c+='<table name"tblMatrices" id="tblMatrices" border=1>';
  5.                 c+='<tr>';
  6.  
  7.                 c+='<td align="center" valing="middle">';
  8.                 c+='<table name="tblMtzA">';
  9.                 for ( i = 0; i < filA; i++) {
  10.                     c+='<tr>';
  11.                     for ( j = 0; j < colA; j++) {
  12.                         c+='<td><input type="text" size="1" maxlength="2"/></td>';
  13.                     }
  14.                     c+='</tr>';
  15.                 }
  16.                 c+='</table>';
  17.                 c+='</td>';
  18.  
  19.                 c+='<td align="center" valign="middle">';
  20.                 c+='<table name="tblMtzB">';
  21.                 for ( i = 0; i < filB; i++) {
  22.                     c+='<tr>';
  23.                     for ( j = 0; j < colB; j++) {
  24.                         c+='<td><input type="text" size="1" maxlength="2"/></td>';
  25.                     }
  26.                     c+='</tr>';
  27.                 }
  28.                 c+='</table>';
  29.                 c+='</td>';
  30.  
  31.                 c+='<td align="center" valign="middle">';
  32.                 c+='<table name="tblMtzR">';
  33.                 for ( i = 0; i < filA; i++) {
  34.                     c+='<tr>';
  35.                     for ( j = 0; j < colB; j++) {
  36.                         c+='<td><input type="text" size="1" maxlength="2"/></td>';
  37.                     }
  38.                     c+='</tr>';
  39.                 }
  40.                 c+='</table>';
  41.                 c+='</td>';
  42.  
  43.                 c+='</tr>';
  44.                 c+='</table>';
  45.                
  46.                 //var matrices = document.getElementById('tblMatrices');
  47.                 //document.getElementById('divMatrices').innerHTML = matrices;
  48.                 e.innerHTML=c;
  49.  
  50.             }


Un saludo.
__________________
21añero.
HTML/CSS, PHP, JS/jQuery, Mysql; NodeJS/Socket.io (& V8); C++ ; Python (wxpy); Ensamblador.
Músico (clarinetista/pianista) y compositor