I have a function that goes through a set of three text fields
[code=html]<input name=”quantity” type=”text” size=”5″ value=”1″ onblur=”UpdateQty(this)”/>
<input name=”quantity” type=”text” size=”5″ value=”1″ onblur=”UpdateQty(this)”/>
<input name=”quantity” type=”text” size=”5″ value=”1″ onblur=”UpdateQty(this)”/>
yes they all share the name quantity and this is because I will have PHP render more if needed dynamically.
I also have a price of 39.00 for the products and only 1 text box which should display the total.
Here is my javascript function…
[code=html]
function UpdateQty() {
//this will count how many times the PHP while loop has gone through..currently
//the session is set a 3 so it will take out 3 products with a quantity box and
//price of 39.00
var counter = document.forms[0].counter.value;
var i=0;
while (e = document.forms[0].elements[counter++]) {
if (e.type == ‘text’)
{
//if I do this then it does the total for the array value of quantity
//qty = document.forms[0].quantity[0].value;
qty = document.forms[0].quantity[e].value;
totalcost = qty * 45.00;
document.forms[0].elements.total.value = “$”+parseFloat(totalcost).toFixed(2);
}
}
}
I want this function to go through all the quantity fields and then multiply to the price and finally to the total. When I do set the following line
[I] qty = document.forms[0].quantity[e].value;
it give me an error
[I]Error: document.forms[0].quantity[e] has no properties
but if i hardcode only one field of the quantity such as:
qty = document.forms[0].quantity[0].value;
It does multiply by the quantity of that field and display the total..anyone know how I can go through all the quantity fields and mutiply all those against the product price and display total? thanks any suggestions or help is appreciated.