Ver Mensaje Individual
  #6 (permalink)  
Antiguo 02/11/2011, 17:03
augusto_jaramil
 
Fecha de Ingreso: junio-2004
Ubicación: Ciudad de Panama
Mensajes: 551
Antigüedad: 22 años, 3 meses
Puntos: 8
Respuesta: Lio con document.createElement()

Ok Don Franz1628, ahi va,

Código PHP:
String.prototype.trim = function() { return this.replace(/^s+|s+$/g, ""); };

function 
crearFilas() {

   var 
reporte = document.getElementById("reporte");

   var 
grups = document.getElementById("grupos").value;
   
str = grups.trim();
   var 
grups = str;

   var 
cols = document.getElementById("cols").value;
   
str = cols.trim();
   var 
cols = str;

   
tbl = document.createElement("table");
   
tr = document.createElement("tr");

   
i = 0;
   
k = 1;
   
largo = ((140*cols)+(3*cols));
   for (
i=0;i<grups;i++) {
       
idnameg="grp"+k+"_0";
       
nuevoTD = document.createElement("td");
            
nuevoTD.setAttribute("colspan", cols);
       
tbl.appendChild(nuevoTD);

       
input = document.createElement("input");
            
input.setAttribute("type", "text");
            
input.setAttribute("id", idnameg);
            
input.setAttribute("name", idnameg);
            
input.setAttribute("value", "Titulo Grupo "+k);
            
input.setAttribute("class", "claseinput");
            
estilo = "text-align:center; width:"+largo+"px; color:blue;";
            
input.setAttribute("style", estilo);
            
input.setAttribute("onChange", "verificaInput(idnameg);");
       
nuevoTD.appendChild(input);
       
tbl.appendChild(nuevoTD);
       
k++;
   }
   
tbl.appendChild(tr);

   
tr = document.createElement("tr");

   
k = 1;
   
g = 1;
   
col_orig = cols;
   
cols = grups*cols;
   for (
j=0;j<cols;j++) {
       
idnamec = "col"+k+"_"+g;
       
nuevoTD = document.createElement("td");
            
nuevoTD.setAttribute("colspan", "1");
       
tbl.appendChild(nuevoTD);

       
input = document.createElement("input");
            
input.setAttribute("type", "text");
            
input.setAttribute("id", idnamec);
            
input.setAttribute("name", idnamec);
            
input.setAttribute("value", "Titulo Columna "+k);
            
input.setAttribute("class", "claseinput");
            
input.setAttribute("style", "width:140px; text-align:center; color:red;");
            
input.setAttribute("onChange", "verificaInput(idnamec);");
       
nuevoTD.appendChild(input);
       
tbl.appendChild(nuevoTD);
       
k = k+1;
       if (
k>col_orig) {
          
g = g+1;
          
k=1;
       }
   }
   
tbl.appendChild(tr);

   
tr = document.createElement("tr");
   
k = 1;
   
g = 1;
   for (
j=0;j<cols;j++) {
       
idnames = "sel"+k+"_"+g;
       
nuevoTD = document.createElement("td");
            
nuevoTD.setAttribute("colspan", "1");
       
tbl.appendChild(nuevoTD);

       
nuevoSelect = document.createElement("select");
            
nuevoTD.setAttribute("id", idnames);
            
nuevoTD.setAttribute("name", idnames);
            
nuevoTD.setAttribute("onChange", "verificaInput(idnames);");

       
opt = document.createElement("Option");
         
opt.setAttribute("value", "Seleccione Filtro");
         
opt.innerHTML="Seleccione Filtro";
         
opt.setAttribute("selected", "");
       
nuevoSelect.appendChild(opt);

       
opt = document.createElement("Option");
         
opt.setAttribute("value", "Query");
         
opt.innerHTML="Query";
       
nuevoSelect.appendChild(opt);

       
opt = document.createElement("Option");
         
opt.setAttribute("value", "Formula");
         
opt.innerHTML="Formula";
       
nuevoSelect.appendChild(opt);

       
opt = document.createElement("Option");
         
opt.setAttribute("value", "Copiar Desde Otra Columna");
         
opt.innerHTML="Copiar Desde Columna";
       
nuevoSelect.appendChild(opt);

       
nuevoTD.appendChild(nuevoSelect);
       
tbl.appendChild(nuevoTD);
       if (
k>col_orig) {
          
g = g+1;
          
k=1;
       }
   }
   
tbl.appendChild(tr);

   
tr = document.createElement("tr");

   
k = 1;
   
g = 1;
   for (
j=0;j<cols;j++) {
       
idnamet = "txt"+k+"_"+g;
       
nuevoTD = document.createElement("td");
            
nuevoTD.setAttribute("colspan", "1");
       
tbl.appendChild(nuevoTD);

       
textarea = document.createElement("textarea");
            
textarea.setAttribute("id", idnamet);
            
textarea.setAttribute("name", idnamet);
            
textarea.setAttribute("rows", "30");
            
textarea.setAttribute("cols", "17");
            
textarea.setAttribute("onChange", "verificaInput(idnamet);");
            
textarea.setAttribute("disabled", "disabled");
       
nuevoTD.appendChild(textarea);
       
tbl.appendChild(nuevoTD);
       
k = k+1;
       if (
k>col_orig) {
          
g = g+1;
          
k=1;
       }
   }
   
tbl.appendChild(tr);
   
reporte.appendChild(tbl);

   
reporte.style.display = "block";
}

function 
verificaInput(id) {
alert(id);
   
alert(document.getElementById(id).value);
}