Ver Mensaje Individual
  #8 (permalink)  
Antiguo 02/11/2011, 20:09
Avatar de Franz1628
Franz1628
 
Fecha de Ingreso: marzo-2007
Ubicación: Lima - Perú
Mensajes: 145
Antigüedad: 17 años, 1 mes
Puntos: 26
Respuesta: Lio con document.createElement()

Ya estaba bien , sólo faltaba añadir los <td> a los <tr> y no los <td> a <table> como esta en tu codigo.

Este es el nuevo código
Código Javascript:
Ver original
  1. String.prototype.trim = function() { return this.replace(/^s+|s+$/g, ""); };
  2.  
  3. function crearFilas() {
  4.  
  5.    var reporte = document.getElementById("reporte");
  6.  
  7.    var grups = document.getElementById("grupos").value;
  8.    str = grups.trim();
  9.    var grups = str;
  10.  
  11.    var cols = document.getElementById("cols").value;
  12.    str = cols.trim();
  13.    var cols = str;
  14.  
  15.    tbl = document.createElement("table");
  16.    tr = document.createElement("tr");
  17.  
  18.    i = 0;
  19.    k = 1;
  20.    largo = ((140*cols)+(3*cols));
  21.    for (i=0;i<grups;i++) {
  22.        idnameg="grp"+k+"_0";
  23.        nuevoTD = document.createElement("td");
  24.             nuevoTD.setAttribute("colspan", cols);
  25.        tbl.appendChild(nuevoTD);
  26.  
  27.        input = document.createElement("input");
  28.             input.setAttribute("type", "text");
  29.             input.setAttribute("id", idnameg);
  30.             input.setAttribute("name", idnameg);
  31.             input.setAttribute("value", "Titulo Grupo "+k);
  32.             input.setAttribute("class", "claseinput");
  33.             estilo = "text-align:center; width:"+largo+"px; color:blue;";
  34.             input.setAttribute("style", estilo);
  35.             input.setAttribute("onChange", "verificaInput(idnameg);");
  36.        nuevoTD.appendChild(input);
  37.        tr.appendChild(nuevoTD);
  38.        k++;
  39.    }
  40.    
  41.    tbl.appendChild(tr);
  42.  
  43.    tr = document.createElement("tr");
  44.  
  45.    k = 1;
  46.    g = 1;
  47.    col_orig = cols;
  48.    cols = grups*cols;
  49.    for (j=0;j<cols;j++) {
  50.        idnamec = "col"+k+"_"+g;
  51.        nuevoTD = document.createElement("td");
  52.             nuevoTD.setAttribute("colspan", "1");
  53.        tbl.appendChild(nuevoTD);
  54.  
  55.        input = document.createElement("input");
  56.             input.setAttribute("type", "text");
  57.             input.setAttribute("id", idnamec);
  58.             input.setAttribute("name", idnamec);
  59.             input.setAttribute("value", "Titulo Columna "+k);
  60.             input.setAttribute("class", "claseinput");
  61.             input.setAttribute("style", "width:140px; text-align:center; color:red;");
  62.             input.setAttribute("onChange", "verificaInput(idnamec);");
  63.        nuevoTD.appendChild(input);
  64.        tr.appendChild(nuevoTD);
  65.        k = k+1;
  66.        if (k>col_orig) {
  67.           g = g+1;
  68.           k=1;
  69.        }
  70.    }
  71.    tbl.appendChild(tr);
  72.  
  73.    tr = document.createElement("tr");
  74.    k = 1;
  75.    g = 1;
  76.    for (j=0;j<cols;j++) {
  77.        idnames = "sel"+k+"_"+g;
  78.        nuevoTD = document.createElement("td");
  79.             nuevoTD.setAttribute("colspan", "1");
  80.        tr.appendChild(nuevoTD);
  81.  
  82.        nuevoSelect = document.createElement("select");
  83.             nuevoTD.setAttribute("id", idnames);
  84.             nuevoTD.setAttribute("name", idnames);
  85.             nuevoTD.setAttribute("onChange", "verificaInput(idnames);");
  86.  
  87.        opt = document.createElement("Option");
  88.          opt.setAttribute("value", "Seleccione Filtro");
  89.          opt.innerHTML="Seleccione Filtro";
  90.          opt.setAttribute("selected", "");
  91.        nuevoSelect.appendChild(opt);
  92.  
  93.        opt = document.createElement("Option");
  94.          opt.setAttribute("value", "Query");
  95.          opt.innerHTML="Query";
  96.        nuevoSelect.appendChild(opt);
  97.  
  98.        opt = document.createElement("Option");
  99.          opt.setAttribute("value", "Formula");
  100.          opt.innerHTML="Formula";
  101.        nuevoSelect.appendChild(opt);
  102.  
  103.        opt = document.createElement("Option");
  104.          opt.setAttribute("value", "Copiar Desde Otra Columna");
  105.          opt.innerHTML="Copiar Desde Columna";
  106.        nuevoSelect.appendChild(opt);
  107.  
  108.        nuevoTD.appendChild(nuevoSelect);
  109.        tr.appendChild(nuevoTD);
  110.        if (k>col_orig) {
  111.           g = g+1;
  112.           k=1;
  113.        }
  114.    }
  115.    tbl.appendChild(tr);
  116.  
  117.    tr = document.createElement("tr");
  118.  
  119.    k = 1;
  120.    g = 1;
  121.    for (j=0;j<cols;j++) {
  122.        idnamet = "txt"+k+"_"+g;
  123.        nuevoTD = document.createElement("td");
  124.             nuevoTD.setAttribute("colspan", "1");
  125.        tr.appendChild(nuevoTD);
  126.  
  127.        textarea = document.createElement("textarea");
  128.             textarea.setAttribute("id", idnamet);
  129.             textarea.setAttribute("name", idnamet);
  130.             textarea.setAttribute("rows", "30");
  131.             textarea.setAttribute("cols", "17");
  132.             textarea.setAttribute("onChange", "verificaInput(idnamet);");
  133.             textarea.setAttribute("disabled", "disabled");
  134.        nuevoTD.appendChild(textarea);
  135.        tr.appendChild(nuevoTD);
  136.        k = k+1;
  137.        if (k>col_orig) {
  138.           g = g+1;
  139.           k=1;
  140.        }
  141.    }
  142.    tbl.appendChild(tr);
  143.    reporte.appendChild(tbl);
  144.  
  145.    reporte.style.display = "block";
  146. }
  147.  
  148. function verificaInput(id) {
  149. alert(id);
  150.    alert(document.getElementById(id).value);
  151. }
__________________
En mi Blog puedes ver articulos javascript y más...
@Franz1628