Foros del Web » Programando para Internet » Javascript »

Cajas de textos Dinamicas

Estas en el tema de Cajas de textos Dinamicas en el foro de Javascript en Foros del Web. Hola amigos de la programacion mi tema es un poco dificil pero se que para muchos no lo es. Solicito ayuda de ustedes ya que ...
  #1 (permalink)  
Antiguo 11/08/2015, 15:32
 
Fecha de Ingreso: julio-2015
Ubicación: Colombia Bogota
Mensajes: 72
Antigüedad: 8 años, 9 meses
Puntos: 0
Cajas de textos Dinamicas

Hola amigos de la programacion
mi tema es un poco dificil pero se que para muchos no lo es.

Solicito ayuda de ustedes ya que tengo este codigo para generar cajas
demo
Código HTML:
Ver original
  1.     <title>Demo: manipulacion de DOM en tablas con MooTools version 0.1.1</title>
  2. <!-----------Nuevas cajas de texto-------------------------------------------------------------------------------------------------------------------------------------------------------------------->
  3.     <script type="text/javascript" src="lib/mootools-release-1.11.js"></script>
  4.     <script type="text/javascript" src="dom_tabla-0.2.js"></script>
  5.     <script type="text/javascript">
  6.     ////////////////////////////////////////////////////////////////////////////////
  7.     function obtEstructuraRegistro(tablaId)
  8.     {
  9.         var registro = new Array();
  10.         if(tablaId == "lista_integrantes")
  11.         {
  12.             registro[0] = { 'elemento': 'input',
  13.                     'type'    : 'checkbox',
  14.                     'id'      : 'marca',
  15.                     'name'    : 'marca' };
  16.  
  17.             registro[1] = { 'elemento'  : 'input',
  18.                     'validador' : 'numbers',
  19.           'type'      : 'text',
  20.                     'id'        : 'cantidad[]',
  21.                     'name'      : 'cantidad[]',
  22.                     'style'     : 'font-size: 11px',
  23.                     'value'     : '',
  24.                     'size'      : '20',
  25.                     'maxlength' : '60' };
  26.        
  27.             registro[2] = { 'elemento'  : 'textarea',
  28.                     'type'      : 'textarea',
  29.                     'id'        : 'descripcion[]',
  30.                     'name'      : 'descripcion[]',
  31.                     'style'     : 'font-size: 11px',
  32.                     'value'     : '',
  33.                     'size'      : '20',
  34.                     'maxlength' : '60' };
  35.            
  36.             registro[3] = { 'elemento'  : 'input',
  37.                     'validador' : 'numbers',
  38.                     'type'      : 'text',
  39.                     'id'        : 'inicial[]',
  40.                     'name'      : 'inicial[]',
  41.                     'style'     : 'font-size: 11px',
  42.                     'value'     : '',
  43.                     'size'      : '4',
  44.                     'maxlength' : '4' };
  45.  
  46.                     registro[4] = { 'elemento'  : 'input',
  47.                     'validador' : 'numbers',
  48.                     'type'      : 'text',
  49.                     'id'        : 'final[]',
  50.                     'name'      : 'final[]',
  51.                     'style'     : 'font-size: 11px',
  52.                     'value'     : '',
  53.                     'size'      : '4',
  54.                     'maxlength' : '4' };
  55.             return registro;
  56.         }
  57.         return null;
  58.     }
  59.     function obtPropiedadesCampo(tablaId)
  60.     {
  61.         if (tablaId == "lista_integrantes")
  62.         {
  63.             return {'class': 'celda_normal'};
  64.         }
  65.         return null;
  66.     }
  67.     function obtPropiedadesFila(tablaId)
  68.     {
  69.         if (tablaId == "lista_integrantes")
  70.         {
  71.             return {}
  72.         }
  73.         return null;
  74.     }
  75.     ////////////////////////////////////////////////////////////////////////////////
  76.     </script>
  77.    
  78. </head>
  79. <form name="form1" method="POST" action="demo2.php">  
  80. <table id="lista_integrantes"  border="1" >
  81.     <tr class="TDCabecera">
  82.         <td  class="titulo_columna">Eliminar</td>
  83.         <td  class="titulo_columna">Cantidad</td>
  84.         <td  class="titulo_columna">Descripcion</td>
  85.     <td  class="titulo_columna">Inicial</td>
  86.         <td  class="titulo_columna">Final</td>
  87.     </tr>
  88.  
  89. <br />
  90.  
  91. <div>
  92.     <input type="button" value="Agregar" onclick="TDAgregarRegistro('lista_integrantes')" />&nbsp;
  93.     <input type="button" value="Remover" onclick="TDRemoverRegistros('lista_integrantes')" />
  94.   <input type='submit' value='Envia' > <input type='reset' value='borrar'>
  95. </div>
  96. </form>
  97. <!------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->
  98.  
  99.  
  100. </body>
  101. </html>

Código Javascript:
Ver original
  1. ////////////////////////////////////////////////////////////////////////////////
  2.  
  3. function TDAgregarRegistro(tablaId)
  4. {
  5.     var tabla = $(tablaId);
  6.     var cabecera = $$("#" + tablaId + " #cabecera");
  7.    
  8.     var estructura = obtEstructuraRegistro(tablaId);
  9.  
  10.     if(estructura == null)
  11.     {
  12.         alert("ERROR obteniendo al estructura de '" + tablaId + "'.");
  13.        
  14.         return false;
  15.     }
  16.    
  17.     var registro = new Element('tr', (obtPropiedadesFila(tablaId) != null) ? obtPropiedadesFila(tablaId) : {});
  18.     registro.setProperty('class', registro.getProperty('class') + " TDRegistro");
  19.    
  20.     for(i=0; i<estructura.length; i++)
  21.     {
  22.         var tipo = estructura[i]['elemento'];
  23.        
  24.         delete(estructura[i]['elemento']);
  25.        
  26.         if(tipo == undefined)
  27.         {
  28.             alert("ERROR obteniendo el tipo del elemento #" + i + " de '" + tablaId + "'.");
  29.            
  30.             return false;
  31.         }
  32.        
  33.         var campo = new Element('td', (obtPropiedadesCampo(tablaId) != null) ? obtPropiedadesCampo(tablaId) : {});
  34.         campo.setProperty('class', campo.getProperty('class') + " TDCampo");
  35.        
  36.         if (estructura[i]['id'] == "marca")
  37.         {
  38.             campo.setStyle('text-align', 'center');
  39.             campo.setProperty('class', campo.getProperty('class') + " TDMarca");
  40.         }
  41.        
  42.         var obj = new Element(tipo, estructura[i]);
  43.        
  44.         if(tipo == "select")
  45.         {
  46.             var opciones = new Array();
  47.            
  48.             if (estructura[i]['items'] != undefined )
  49.             {
  50.                 opciones = $H(estructura[i]['items']);
  51.  
  52.                 delete(estructura[i]['items'])
  53.             }
  54.        
  55.             opciones.each(function(valor, llave)
  56.             {
  57.                 var option = new Element('option', {'value': valor});
  58.                 option.setText(llave);
  59.                
  60.                 option.injectInside(obj);
  61.             });
  62.         }
  63.        
  64.         obj.injectInside(campo);
  65.        
  66.         if(estructura[i]['validador'])
  67.         {
  68.             var validador = estructura[i]['validador'];
  69.        
  70.             obj.addEvent('keydown', function(e)
  71.             {
  72.                 var ev = new Event(e);
  73.                
  74.                 if(ev.code < 32)
  75.                     return false;
  76.                
  77.                 // var valor = String.fromCharCode(ev.code);
  78.                 var valor = (ev.shift) ? ev.key.toUpperCase() : ev.key.toLowerCase();
  79.  
  80.                 var control = TDValidarDato(valor, validador, null);
  81.                
  82.                 if (!control)
  83.                     ev.stop();
  84.                    
  85.                 return control;
  86.             });
  87.              
  88.             delete(estructura[i]['validador']);
  89.         }
  90.        
  91.         campo.injectInside(registro);
  92.     }
  93.    
  94.     registro.injectInside(tabla.getElement("tbody"));
  95. }
  96.  
  97. function TDRemoverRegistros(tablaId)
  98. {
  99.     var marcas = $$("#" + tablaId + " .TDMarca");
  100.  
  101.     var cantidad = 0;
  102.    
  103.     marcas.each(function(elemento, indice)
  104.     {
  105.         var marca = elemento.getElement("input[id=marca]");
  106.        
  107.         if(!marca.getProperty('checked'))
  108.             return;
  109.            
  110.         cantidad ++;
  111.        
  112.         var tr = elemento.getParent();
  113.    
  114.         tr.remove();
  115.     });
  116.    
  117.     if(cantidad == 0)
  118.         alert("Por favor seleccione las marcas de verificacion\n" +
  119.               "de los elementos que desea remover.");
  120.              
  121.     return cantidad;
  122. }
  123.  
  124. ////////////////////////////////////////////////////////////////////////////////
  125.  
  126. function TDValidarDato(value, type, options)
  127. {
  128.     var regexp = null;
  129.    
  130.     switch(type)
  131.     {
  132.         case 'numbers':             regexp = /^\d+$/; break;
  133.         case 'no_numbers':      regexp = /^\D+$/; break;
  134.         case 'letters_lowercase':   regexp = /^[a-z]+$/; break;
  135.         case 'letters_uppercase':   regexp = /^[A-Z]+$/; break;
  136.         case 'letters_full':        regexp = /^[A-Za-z]+$/; break;
  137.         case 'numbers_letters':     regexp = /^[A-Za-z0-9]+$/; break;
  138.         case 'regexp':          regexp = /options/; break;
  139.     }
  140.    
  141.     if(regexp == null)
  142.     {
  143.         alert("type is invalid: " + type);
  144.         return false;
  145.     }
  146.    
  147.     return regexp.test(value);
  148. }
  149.  
  150. ////////////////////////////////////////////////////////////////////////////////

necesito sumar la casilla de cantidad + la casilla inicial y en la caja final aparesca el resultado, y la caja final este readonly="readonly".

Gracias amigos espero me puedan ayudar

Etiquetas: cajas, dinamicas, html, input, js, php, select, textos, valor
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 15:22.