|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Junior Member
Iscritto dal: May 2007
Messaggi: 17
|
Aiuto calcolo del totale con javascript!!!!!!!
Salve a tutti!!
qlcn sa dirmi come si calcola un totale del genere con javascript?Un metodo facile ?? Falanghina ______ a 8.75 euro la bottiglia ______ Taurasi ______ a 9.59 euro la bottiglia ______ Coda di Volpe ______ a 7.25 euro la bottiglia ______ Totale:______ praticamente viene inserito una quantità(nr bottiglie),con l'evento onchange deve comparire sia il prezzo per quel tipo di vino sia il totale in basso;a qualsiasi modifica si deve aggiornare anche il totale....Questo è il codice html.... Codice HTML:
<head> <title>Vini Radio</title> </head> <body> <form name="vini"> <table> <tr> <td>Falanghina</td><td><input type="text" size="3" id="quantita1" name="vino1" onkeyup="calcolo()"></td> <td>a 8.75 euro la bottiglia</td><td><input type="text" id="parziale1" name="totvino1" size="5" ></td> </tr> <tr> <td>Taurasi</td><td><input type="text" size="3" id="quantita2" name="vino2" onkeyup="calcolo()"></td> <td>a 9.59 euro la bottiglia</td><td><input type="text" id="parziale2" name="totvino2" size="5" ></td> </tr> <tr> <td>Coda di Volpe</td><td><input type="text" size="3" id="quantita3" name="vino3" onkeyup="calcolo(this)"></td> <td>a 7.25 euro la bottiglia</td><td><input type="text" id="parziale3" name="totvino3" size="5" ></td> </tr> </table> <br><br> Totale:<input type="text" size="5" id="tot" name="totaleP" onchange="calcolo()"><br><br> </table> </form> </body> Chiedo il vostro aiuto,la funzione "calcolo" in javascript....con quele regole (dette sopra)!! grazie |
|
|
|
|
|
#2 | |
|
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
Quote:
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>
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
|
|
|
|
|
|
#3 |
|
Junior Member
Iscritto dal: May 2007
Messaggi: 17
|
Benissimo!!!!
velocissimo!!! facilissimo!!! grazie 1000!!! |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 19:30.




















