Ver Mensaje Individual
  #5 (permalink)  
Antiguo 20/10/2014, 15:59
EdyArgueta
 
Fecha de Ingreso: abril-2014
Mensajes: 51
Antigüedad: 10 años
Puntos: 1
Respuesta: input dinamico con eventos onkeyup de multiplicar

jejeje si creo que no explique bien pero ya tengo la solucion este es el resultado que esperaba y su solucion.



yo tengo un boton que crea inputs, estos son cantidad precio y total osea que tendre esos inputs idefinidamente repetidos, la idea es multiplicar cantidad por precio automaticamente tenia un codigo para multiplicar pero al ser dinamicos los inputs los creo por medio de javascript el detalle era que no sabia como ingresar ese codigo que multiplica a los inputs por java... asi que el resultado fue este


Código:
<script type="text/javascript">

icremento =0;
function crear(obj) {
icremento++;
field = document.getElementById('field'); 
contenedor = document.createElement('div'); 
contenedor.id = 'div'+icremento; 
field.appendChild(contenedor);

var calculoc = 'if(agregar.p'+ +icremento +'.value!=""){agregar.t'+ +icremento +'.value = parseFloat(this.value)*parseFloat(agregar.p'+ +icremento +'.value)}' ;
var calculop = 'if(agregar.c'+ +icremento +'.value!=""){agregar.t'+ +icremento +'.value = parseFloat(this.value)*parseFloat(agregar.c'+ +icremento +'.value)}' ;

boton = document.createElement('input');
boton.type = 'text';
boton.id = 'c'+icremento; 
boton.name = 'c'+'[]';
boton.size='5';
boton.setAttribute('onKeyUp',calculoc);
contenedor.appendChild(boton); 

boton = document.createElement('input'); 
boton.type = 'text'; 
boton.name = 'd'+'[]'; 
boton.size='48';
boton.required=true;
contenedor.appendChild(boton);

boton = document.createElement('input'); 
boton.type = 'text'; 
boton.name = 'm'+'[]'; 
boton.size='6';
contenedor.appendChild(boton);

boton = document.createElement('input'); 
boton.type = 'text';
boton.id = 'p'+icremento;
boton.setAttribute('onKeyUp',calculop);
boton.name = 'p'+'[]'; 
boton.size='6';
boton.required=true;
contenedor.appendChild(boton);

boton = document.createElement('input'); 
boton.type = 'text';
boton.id = 't'+icremento; 
boton.name = 't'+'[]'; 
boton.size='6';
boton.required=true;
boton.readOnly=true;
contenedor.appendChild(boton);

boton = document.createElement('input'); 
boton.type = 'button'; 
boton.value = 'Borrar'; 
boton.name = 'div'+icremento; 
boton.onclick = function () {borrar(this.name)} 
contenedor.appendChild(boton); 

}
function borrar(obj) {
field = document.getElementById('field'); 
field.removeChild(document.getElementById(obj)); 
}
</script>
basicamente era error de sintaxis, pero gracias por tu ayuda y tiempo igual le dare uso a tu codigo