View Single Post
Old 04-06-2007, 19:57   #2
andbin
Senior Member
 
L'Avatar di andbin
 
Iscritto dal: Nov 2005
Messaggi: 5206
Quote:
Originariamente inviato da felgiro Guarda i messaggi
qlcn sa dirmi come si calcola un totale del genere con javascript?Un metodo facile ??
Prova questa paginetta che ho fatto:
Codice:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Ordine</title>
<script type="text/javascript">
<!--
function calcolo ()
{
    var quantita1 = parseFloat (document.ordine.quantita1.value);
    var quantita2 = parseFloat (document.ordine.quantita2.value);

    if (isNaN (quantita1))
        quantita1 = 0.0;

    if (isNaN (quantita2))
        quantita2 = 0.0;

    var totprod1 = 8.75 * quantita1;
    var totprod2 = 9.59 * quantita2;
    var totaleP = totprod1 + totprod2;

    document.ordine.quantita1.value = quantita1;
    document.ordine.quantita2.value = quantita2;
    document.ordine.totprod1.value = totprod1;
    document.ordine.totprod2.value = totprod2;
    document.ordine.totaleP.value = totaleP;
}
//-->
</script>
</head>
<body onload="calcolo()">

<form name="ordine">

<table border="0" cellspacing="0" cellpadding="6">
  <tr>
    <td>Bottiglia A</td>
    <td><input type="text" size="3" id="quantita1" name="prod1" onkeyup="calcolo()"></td>
    <td>a 8.75 euro la bottiglia</td>
    <td><input type="text" name="totprod1" size="5" readonly="readonly"></td>
  </tr>
  <tr>
    <td>Bottiglia B</td>
    <td><input type="text" size="3" id="quantita2" name="prod2" onkeyup="calcolo()"></td>
    <td>a 9.59 euro la bottiglia</td>
    <td><input type="text" name="totprod2" size="5" readonly="readonly"></td>
  </tr>
</table>

<br>
<br>

Totale: <input type="text" size="5" name="totaleP" readonly="readonly">
</form>

</body>
</html>
Chiaramente, richiede un minimo di adattamento alla tua.
__________________
Andrea, Senior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
Java Versions Cheat Sheet
andbin è offline   Rispondi citando il messaggio o parte di esso