Hallo
Ich habe im html mehrmals hintereinander die folgenden drei input-Felder: Anzahl, Preis, Total. Die Anzahl wird vom user eingegeben, der Preis ist schon drin und das Total soll berechnet werden.
Unten ist der js und html Code. Meine for-Schleife scheint zwar die var richtig zusammen zu setzen, aber die Berechnungen werden nicht durchgefuehrt. Wie kann ich dieses Problem loesen?
Vielen Dank fuer eure Hilfe.
Margrit
function compute() {
var c = 1;
for(i = 0; i < 5; i ++){
str1 = "document.calc.";
str2 = ".value";
str3 = "anzahl";
str4 = "total";
str5 = "preis";
n_anzahl = str1.concat(str3).concat(c).concat(str2);
n_preis = str1.concat(str5).concat(c).concat(str2);
n_total = str1.concat(str4).concat(c).concat(str2);
n_total = n_anzahl * n_preis;
c ++;
}
}
html:
<TABLE>
<TR>
<TD>
<DIV ALIGN=CENTER>Anzahl</DIV>
</TD>
<TD>
<DIV ALIGN=CENTER>Preis</DIV>
</TD>
<TD>
<DIV ALIGN=CENTER>Total</DIV>
</TD>
<TD>
</TD>
</TR>
<FORM action="" method=POST name="calc">
<TR>
<TD>
<INPUT TYPE="TEXT" NAME="anzahl1" SIZE="6" onChange="compute()">
</TD>
<TD>
<INPUT TYPE="TEXT" NAME="preis1" SIZE="9" value="20" readonly >
</TD>
<TD>
<INPUT TYPE="TEXT" NAME="total1" SIZE="9" onChange="compute()">
</TD>
</TR>
<TR>
<TD>
<INPUT TYPE="TEXT" NAME="anzahl2" SIZE="6" onChange="compute()">
</TD>
<TD>
<INPUT TYPE="TEXT" NAME="preis2" SIZE="9" value="20" readonly >
</TD>
<TD>
<INPUT TYPE="TEXT" NAME="total2" SIZE="9" onChange="compute()">
</TD>
</TR>
<!-- Hier folgen noch weitere TR -->
</FORM>
</TABLE>