Cita:
Iniciado por faseb
este es el script el cual multiplica
<script>
function calcula(){
var cantidad = document.getElementById('CANTIDAD').value;
var precio = document.getElementById('PRECIO').innerHTML;
var decimal = parseFloat('precio');
var subtotal = cantidad_decimal * decimal
document.getElementById('SUBTOTAL').value = subtotal
}
</script>
ak la parte q envia al script
<td><div id="PRECIO" onKeyPress="calcula(this.value);"></div></td>// ak recibo el valor desde ajax
<td> </td>
<td><input type="text" name="CANTIDAD" id="CANTIDAD" value="" onChange="calcula()"></td>
<td> </td>
<td><input type="number" name="SUBTOTAL" id="SUBTOTAL" value=""></td>
si necesitas algo mas pedime. los valores q tengo son 4.00 , 5.99 , 10.50
tenés una gran confusión
esto
onKeyPress="calcula(this.value)"
en un div no se ejecuta
los parseFloat tenés que hacércelos a los valores (del div id="PRECIO" y el input id="CANTIDAD"), pero como estos valores los estás poniendo en sendas variables, el parseFLoat en definitiva se hace a las variables, que son
cantidad y
precio, sin las comillas !!! El parámetro
operacion carece de sentido, al menos en lo que proponés
El evento a utilizar es onkeyup para este caso, en definitiva
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"> //<![CDATA[
function calcula(operacion){
var cantidad = document.getElementById('CANTIDAD').value;
var cantidad_decimal = parseFloat(cantidad);
var precio = document.getElementById('PRECIO').innerHTML;
var decimal = parseFloat(precio);
var subtotal = cantidad * decimal
document.getElementById('SUBTOTAL').value = subtotal
}
//]]>
<td><input type="text" name="CANTIDAD" id="CANTIDAD" value="" onkeyup="calcula()" /></td> <td><input type="text" name="SUBTOTAL" id="SUBTOTAL" value="" /></td>
Te recomiendo que empieces con algún buen manual de javascript
SAludos