Código Del Documento HTML.: Factura
Código Del Documento HTML.: Factura
</body>
</html>
Código JavaScript
function agregar() {
lista = document.getElementById('productos');
nuevaFila = document.createElement('tr');
cantidad = document.createElement('td');
cantidad.align = 'center';
cantidad.width = '8%';
concepto = document.createElement('td');
concepto.align = 'center';
concepto.width = '52%';
precioUnitario = document.createElement('td');
precioUnitario.align = 'center';
precioUnitario.width = '20%';
valor = document.createElement('input');
valor.type = 'text';
valor.name = 'can[]';
valor.value = '0';
valor.size = '7';
valor.onblur = function() {validarCantidad(this);};
cantidad.appendChild(valor);
valor = document.createElement('input');
valor.type = 'text';
valor.name = 'dep[]';
valor.value = '';
valor.size = '85';
concepto.appendChild(valor);
valor = document.createElement('input');
valor.type = 'text';
valor.name = 'pu[]';
valor.value = '0';
valor.size = '20';
valor.onblur = function() {validarPrecio(this);};
precioUnitario.appendChild(valor);
nuevaFila.appendChild(cantidad);
nuevaFila.appendChild(concepto);
nuevaFila.appendChild(precioUnitario);
lista.appendChild(nuevaFila);
}
function generarFactura() {
function validar(obj) {
if(isNaN(obj.value) || obj.value=='') {
alert('Se admiten unicamente caracteres numericos.');
obj.value = '0';
return 0;
}
if(parseInt(obj.value) < 0) {
alert('Cantidades negativas no validas.');
obj.value = '0';
return 0;
}
}
function validarCantidad(obj) {
if(validar(obj) == 0) {
return;
}
obj.value = parseInt(obj.value,10);
}
function validarPrecio(obj) {
if(validar(obj) == 0) {
return;
}
obj.value = Math.floor(parseFloat(obj.value)*100)/100;
}