• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

[Javascript] Preise berechnen

g554161

Neues Mitglied
Hallo,
ich habe verschiedene Selectboxen, die eine Beschreibung und einen Wert haben. Und jetzt wollte ich das so machen, das wenn man die Sachen auswählen kann, sofort hinten der Preis ausgerechnet wird (Die value der ersten zwei werte soll addiert werden und mit der value der Dritten Selectbox multipliziert).

Ich habe zurzeit folgendes Problem: Nur der Zweite Wert wird mit dem dirtten multipliziert und dann mit dem ersten addiert. Eigentlich sollte es so sein: Die value der ersten zwei werte soll addiert werden und mit der value der Dritten Selectbox multipliziert.

Code:
var summe = 0;
function prepare(){
summe = parseInt(document.all.form1.liste1.value) + parseInt(document.all.form1.liste2.value) * parseInt(document.all.form1.liste3.value);
document.all.summe.innerHTML = summe;
}

function calculate(){
summe = parseInt(document.all.form1.liste1.value) + parseInt(document.all.form1.liste2.value) * parseInt(document.all.form1.liste3.value);
document.all.summe.innerHTML = summe;
}

Würde mich über jede hilfe freuen
Vielen Dank
Mit freundlichen Grüßen
 
Das funktioniert bei mir aber irgendwie nicht

HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Unbenanntes Dokument</title>
<script language="javascript">
var summe = 0;
function prepare(){
summe = parseInt((document.all.form1.liste1.value) + parseInt(document.all.form1.liste2.value)) * parseInt(document.all.form1.liste3.value);
document.all.summe.innerHTML = summe;
}

function calculate(){
summe = parseInt((document.all.form1.liste1.value) + parseInt(document.all.form1.liste2.value)) * parseInt(document.all.form1.liste3.value);
document.all.summe.innerHTML = summe;
}
</script>
</head>

<body onLoad="prepare()">
<form name="form1" method="post" action="">
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><select name="liste1" id="liste1" onChange="calculate()">
<option value="1">artikel1</option>
<option value="2">artikel2</option>
</select></td>
<td><select name="liste2" id="liste2" onChange="calculate()">
<option value="0">0</option>
<option value="1">1</option>
</select></td>
<td><select name="liste3" id="liste3" onChange="calculate()">
<option value="1" selected>artikel3</option>
<option value="2">artikel4</option>
</select></td>
<td><p id="summe">0</p></td>
</tr>
</table>
<br>
</form>
</body>
</html>
 
Mir scheint, Du hast da noch einen Fehler bei der Klammerung. So ist es richtig:
Code:
summe = (parseInt(document.all.form1.liste1.value) + parseInt(document.all.form1.liste2.value)) * parseInt(document.all.form1.liste3.value);
 
Mir scheint, Du hast da noch einen Fehler bei der Klammerung. So ist es richtig:
Code:
summe = (parseInt(document.all.form1.liste1.value) + parseInt(document.all.form1.liste2.value)) * parseInt(document.all.form1.liste3.value);

Das funktioniert leider auch nicht, die Summe beleibt jetzt immer bei 0 egal was ich auswähle.

MfG
 
Kann ich mir gar nicht vorstellen, denn ich hatte es so erfolgreich getestet. Poste doch noch mal deine komplette Seite.
 
HTML:
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>Unbenanntes Dokument</title>
  5. <script language="javascript">
  6. var summe = 0;
  7. function prepare(){
  8. summe =(parseInt(document.all.form1.liste1.value) + parseInt(document.all.form1.liste2.value)) * parseInt(document.all.form1.liste3.value);
  9. document.all.summe.innerHTML = summe;
  10. }

  11. function calculate(){
  12. summe = (parseInt(document.all.form1.liste1.value) + parseInt(document.all.form1.liste2.value)) * parseInt(document.all.form1.liste3.value);
  13. document.all.summe.innerHTML = summe;
  14. }
  15. </script>
  16. </head>

  17. <body onLoad="prepare()">
  18. <form name="form1" method="post" action="">
  19. <br>
  20. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  21. <tr>
  22. <td><select name="liste1" id="liste1" onChange="calculate()">
  23. <option value="1">artikel1</option>
  24. <option value="2">artikel2</option>
  25. </select></td>
  26. <td><select name="liste2" id="liste2" onChange="calculate()">
  27. <option value="0">0</option>
  28. <option value="1">1</option>
  29. </select></td>
  30. <td><select name="liste3" id="liste3" onChange="calculate()">
  31. <option value="1" selected>artikel3</option>
  32. <option value="2">artikel4</option>
  33. </select></td>
  34. <td><p id="summe">0</p></td>
  35. </tr>
  36. </table>
  37. <br>
  38. </form>
  39. </body>
  40. </html>
 
??? Funktioniert bei mir einwandfrei (im FF). Welchen Browser benutzt Du denn? Wirf mal einen Blick in die Fehlerkonsole.
 
Zurück
Oben