Ver Mensaje Individual
  #4 (permalink)  
Antiguo 22/05/2012, 19:29
Avatar de djaevi
djaevi
 
Fecha de Ingreso: marzo-2007
Ubicación: Moreno, Buenos Aires
Mensajes: 400
Antigüedad: 18 años
Puntos: 47
Respuesta: javascript- formulario- crear nuevo

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Facturas</title>
  5.  
  6.     body {
  7.         font-family:"Trebuchet MS";
  8.     }
  9.    
  10.     #cabecera td {
  11.         width:100px;
  12.         padding-right:6px;
  13.         text-align:center;
  14.         background-color:#EFEFEF;
  15.         border:dashed 1px #DEDEDE;
  16.         }
  17.    
  18.     #ElementosFactura input {
  19.         width:100px;
  20.         text-align:center;
  21.         }
  22.        
  23.     .botones {
  24.         border:1px;
  25.         cursor:pointer;
  26.         margin-left:20px;
  27.         }
  28.        
  29.     #totales {
  30.         padding-top:10px;
  31.         width:100%;
  32.         padding-left:386px;
  33.         }
  34.        
  35.     #totales input {
  36.         width:100px;
  37.         }
  38.        
  39.  
  40. <script type="text/javascript">

Código Javascript:
Ver original
  1. function clon(e) {
  2.         var cantForms = document.getElementsByName("FacProvForm").length;
  3.         var clon = e.cloneNode(true);
  4.             clon.Eliminar.onclick = function() {
  5.                 document.getElementById("ElementosFactura").removeChild(this.parentNode);
  6.                 sumar();
  7.             }
  8.         clon.calcular = e.parentNode.calcular;
  9.         clon.cantidad.value = 0;
  10.         clon.costo.value = 0;
  11.         clon.subtotal.value = 0;
  12.         clon.PcioVta.value = 0;
  13.         clon.gcia.value = 0;
  14.         document.getElementById("ElementosFactura").appendChild(clon);  
  15.     }
  16.      
  17.     function assign() {
  18.         document.forms[0].calcular = function() {
  19.             this.Vcantidad = this.cantidad.value;
  20.             this.Vcosto = this.costo.value;
  21.             this.Vsubtotal = this.subtotal.value = (this.Vcantidad * this.Vcosto) ;
  22.             this.VPcioVta = this.PcioVta.value;
  23.             this.Vgcia = this.gcia.value = (((this.VPcioVta / this.Vcosto)-1)*100) ;
  24.         }
  25.         //alert(document.forms[0].calcular);
  26.     }
  27.    
  28.     function sumar() {
  29.         var subtotales= document.getElementsByName("subtotal");
  30.         var suma = 0;
  31.         for (var i=0; i<subtotales.length; i++) {
  32.             suma += Number(subtotales[i].value);
  33.             }
  34.         document.getElementById("sumaTotal").value = suma;
  35.         }

Código HTML:
Ver original
  1.      
  2.     </head>
  3.      
  4.     <body onload="assign();">
  5.      
  6.     <div id="factura" style="width:800px;">  
  7.         <table id="cabecera" border="0" cellspacing="0" cellpadding="0">
  8.             <tr>
  9.                 <td>Cantidad</td>
  10.                 <td>Costo</td>
  11.                 <td>Subtotal</td>
  12.                 <td>Precio de Venta</td>
  13.                 <td>Ganancia</td>
  14.             </tr>
  15.         </table>
  16.         <div id="ElementosFactura">
  17.             <form name="FacProvForm">
  18.                 <input name="cantidad" type="text" onkeyup="this.parentNode.calcular(); sumar();" size="15" value="0">
  19.                 <input name="costo" type="text" onkeyup="this.parentNode.calcular(); sumar();" size="15" value="0">
  20.                 <input name="subtotal" type="text" onkeyup="this.parentNode.calcular(); sumar();" size="15" value="0">
  21.                 <input name="PcioVta" type="text" onkeyup="this.parentNode.calcular(); sumar();" size="15" value="0">
  22.                 <input name="gcia" type="text" onkeyup="this.parentNode.calcular(); sumar();" size="15" value="0">
  23.                 <input class="botones" name="Agregar" type="button" onClick= "clon(this.parentNode);" value="Agregar Item" />
  24.                 <input class="botones" name="Eliminar" type="button" value="Eliminar Item" />
  25.             </form>
  26.         </div>
  27.         <div id="totales">
  28.             Total: <input type="text" id="sumaTotal" />
  29.         </div>
  30.     </div>
  31.     </body>
  32. </html>

Ahi esta fijate si te sirve, lo probe y anda de paso lo estilize un poco jaja

Saludos

Última edición por djaevi; 23/05/2012 a las 06:47