Hola me resulto interesante tu trabajo asi que lo corregi un poco fijate si te sirve y si te hace falta cambiarle algo me avisas ;).
Código HTML:
Ver original<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
Código Javascript
:
Ver originalfunction clon(e) {
var cantForms = document.getElementsByName("FacProvForm").length;
var clon = e.parentNode.cloneNode(true);
clon.Eliminar.onclick = function() {
document.body.removeChild(this.parentNode);
}
clon.calcular = e.parentNode.calcular;
clon.cantidad.value = 0;
clon.costo.value = 0;
clon.subtotal.value = 0;
clon.PcioVta.value = 0;
clon.gcia.value = 0;
document.body.appendChild(clon);
}
function assign() {
document.forms[0].calcular = function() {
this.Vcantidad = this.cantidad.value;
this.Vcosto = this.costo.value;
this.Vsubtotal = this.subtotal.value = (this.Vcantidad * this.Vcosto) ;
this.VPcioVta = this.PcioVta.value;
this.Vgcia = this.gcia.value = (((this.VPcioVta / this.Vcosto)-1)*100) ;
}
//alert(document.forms[0].calcular);
}
Código HTML:
Ver original
<body onload="assign();">
<form name="FacProvForm"> <input name="cantidad" type="text" onkeyup="this.parentNode.calcular()" size="15" value="0"> <input name="costo" type="text" onkeyup="this.parentNode.calcular()" size="15" value="0"> <input name="subtotal" type="text" onkeyup="this.parentNode.calcular()" size="15" value="0"> <input name="PcioVta" type="text" onkeyup="this.parentNode.calcular()" size="15" value="0"> <input name="gcia" type="text" onkeyup="this.parentNode.calcular()" size="15" value="0"> <input name="Agregar" type="button" onClick= "clon(this);" value="Agregar Item" /> <input name="Eliminar" type="button" value="Eliminar Item" />
Ahora mismo me estoy yendo si necesitas que te explique como funciona el codigo me avisas
SALUDOS