Forum Moderators: open
document.orderDetails.ItemTotal[i].value
Here's the statement in context...
var allItemCost = document.getElementsByName("ItemCost[]");
for (var i=0; i < allItemCost.length; i++)
{
document.orderDetails.ItemTotal[i].value =
parseFloat(document.orderDetails.ItemCost[i].value) *
parseFloat(document.orderDetails.ItemQuantity[i].value) *
( 1 - ( parseFloat(document.orderDetails.ItemDiscount[i].value)/100 ) );
}
Any ideas?
Cheers, Pete
That statement is going to find elements that have a name value of "ItemCost[]". In other words, it will not match elements with names like "ItemCost[1]" or "ItemCost[2]".
The statement:
document.orderDetails.ItemTotal[i].value = ...;
will not work as you'd like. Try this instead:
document.orderDetails['ItemTotal[' + i + ']'].value = ...;
HTML looks like this....
<form name="orderDetails" action="protxautoform.php" method="POST">
...
<input type="hidden" name="ItemName[]" value="Some stuff">
<input type="hidden" name="ItemCost[]" value="8.00">
<input type="hidden" name="ItemQuantity[]" value="1">
<input type="hidden" name="ItemSubTotal[]" value="8.00">
<input type="text" name="ItemDiscount[]" value="0" onFocus="startCalc();" onBlur="stopCalc();">
<input type="text" name="ItemTotal[]" size="5" readonly>
...
</form>
The input fields above repeat (they are in a table of cart items).
Cheers, Pete
var allItemTotal = document.getElementsByName('ItemTotal[]');
allItemTotal[i].value = ...;