Piotto
11-08-2009, 09:29 AM
Hi everybody. As a beginner i am trying to understand a tutorial i found about calculation in a form. Now, I got the code working, but only if there is one line to calculate (only with PRODUCT 1 for example).
Why? How can i have the code working for any number of products no matter how many?
Here is the code...
[CODE]
<HTML>
<HEAD>
<SCRIPT language = JavaScript>
function calculate2() {
A = document.catalogo1.itemprice.value
B = document.catalogo1.itemquantity.value
A = Number(A)
B = Number(B)
C = (A * B)
document.catalogo1.subtotal.value = C
}
</SCRIPT>
</HEAD>
<BODY onload = calculate2()>
<FORM NAME = catalogo1>
PRODUCT 1 - Price: <INPUT readonly TYPE = Text NAME = itemprice SIZE = 5 value ="75.50" onkeyup = calculate2()> X Quantity: <INPUT TYPE = Text NAME = itemquantity SIZE = 5 value ="2"> = SubTotal: <INPUT readonly TYPE = Text NAME = subtotal SIZE = 5 value = ""><br><br>
PRODUCT 2 - Price: <INPUT readonly TYPE = Text NAME = itemprice SIZE = 5 value ="12.85" onkeyup = calculate2()> X Quantity: <INPUT TYPE = Text NAME = itemquantity SIZE = 5 value ="4"> = SubTotal: <INPUT readonly TYPE = Text NAME = subtotal SIZE = 5 value = ""><br><br>
PRODUCT 3 - Price: <INPUT readonly TYPE = Text NAME = itemprice SIZE = 5 value ="25.45" onkeyup = calculate2()> X Quantity: <INPUT TYPE = Text NAME = itemquantity SIZE = 5 value ="7"> = SubTotal: <INPUT readonly TYPE = Text NAME = subtotal SIZE = 5 value = ""><br><br>
PRODUCT 4 - Price: <INPUT readonly TYPE = Text NAME = itemprice SIZE = 5 value ="62.20" onkeyup = calculate2()> X Quantity: <INPUT TYPE = Text NAME = itemquantity SIZE = 5 value ="5"> = SubTotal: <INPUT readonly TYPE = Text NAME = subtotal SIZE = 5 value = "">
</FORM>
</BODY>
</HTML>
[CODE]
Any help will be really appreciated. Thanks
Why? How can i have the code working for any number of products no matter how many?
Here is the code...
[CODE]
<HTML>
<HEAD>
<SCRIPT language = JavaScript>
function calculate2() {
A = document.catalogo1.itemprice.value
B = document.catalogo1.itemquantity.value
A = Number(A)
B = Number(B)
C = (A * B)
document.catalogo1.subtotal.value = C
}
</SCRIPT>
</HEAD>
<BODY onload = calculate2()>
<FORM NAME = catalogo1>
PRODUCT 1 - Price: <INPUT readonly TYPE = Text NAME = itemprice SIZE = 5 value ="75.50" onkeyup = calculate2()> X Quantity: <INPUT TYPE = Text NAME = itemquantity SIZE = 5 value ="2"> = SubTotal: <INPUT readonly TYPE = Text NAME = subtotal SIZE = 5 value = ""><br><br>
PRODUCT 2 - Price: <INPUT readonly TYPE = Text NAME = itemprice SIZE = 5 value ="12.85" onkeyup = calculate2()> X Quantity: <INPUT TYPE = Text NAME = itemquantity SIZE = 5 value ="4"> = SubTotal: <INPUT readonly TYPE = Text NAME = subtotal SIZE = 5 value = ""><br><br>
PRODUCT 3 - Price: <INPUT readonly TYPE = Text NAME = itemprice SIZE = 5 value ="25.45" onkeyup = calculate2()> X Quantity: <INPUT TYPE = Text NAME = itemquantity SIZE = 5 value ="7"> = SubTotal: <INPUT readonly TYPE = Text NAME = subtotal SIZE = 5 value = ""><br><br>
PRODUCT 4 - Price: <INPUT readonly TYPE = Text NAME = itemprice SIZE = 5 value ="62.20" onkeyup = calculate2()> X Quantity: <INPUT TYPE = Text NAME = itemquantity SIZE = 5 value ="5"> = SubTotal: <INPUT readonly TYPE = Text NAME = subtotal SIZE = 5 value = "">
</FORM>
</BODY>
</HTML>
[CODE]
Any help will be really appreciated. Thanks