I'm having some trouble with arrays. I'm using JavaScript to add some TEXT INPUT form fields together ONBLUR(), then the total is displayed in a READONLY TEXT INPUT field. The fields that are being added are dynamically generated using PHP and MySQL. That whole PHP part of it works great, but as a result, I need to NAME the fields quantity[0], quantity[1], quantity[2]...
From what I know about JavaScript, this shouldn't be a problem. But it is.
Here's my dynamically generated code:
<form method="POST" action="in-home-date.php" name="locationsform">
<script language=JavaScript>
<!-- Hide
var quantity=new Array(3)
quantity[0]=0;
quantity[1]=0;
quantity[2]=0;
function Calculate()
{ document.locationsform.total_qty.value = (0 +
parsefloat(document.locationsform.quantity[0].value) +
parsefloat(document.locationsform.quantity[1].value) +
parsefloat(document.locationsform.quantity[2].value)); }
// End -->
</script>
<input type=text size=6 value=http://www.webdeveloper.com/forum/archive/index.php/0 name="quantity[0]" onBlur="Calculate();">
<input type=text size=6 value=0 name="quantity[1]" onBlur="Calculate();">
<input type=text size=6 value=0 name="quantity[2]" onBlur="Calculate();">
<b>Total Qty: </b><input value=0 type=text size=7
name="total_qty" readonly>
<input type="submit" value="Submit Locations" /></form>
...and the error message that I'm getting when running the function Calculate() says:
"document.locationsform.quantity.0 is null or not an object"
It seems to be reading the array object number as the value of the field "quantity," a field that, of course, does not exist anywhere in my code.
Did I declare something wrong? What's going on?
From what I know about JavaScript, this shouldn't be a problem. But it is.
Here's my dynamically generated code:
<form method="POST" action="in-home-date.php" name="locationsform">
<script language=JavaScript>
<!-- Hide
var quantity=new Array(3)
quantity[0]=0;
quantity[1]=0;
quantity[2]=0;
function Calculate()
{ document.locationsform.total_qty.value = (0 +
parsefloat(document.locationsform.quantity[0].value) +
parsefloat(document.locationsform.quantity[1].value) +
parsefloat(document.locationsform.quantity[2].value)); }
// End -->
</script>
<input type=text size=6 value=http://www.webdeveloper.com/forum/archive/index.php/0 name="quantity[0]" onBlur="Calculate();">
<input type=text size=6 value=0 name="quantity[1]" onBlur="Calculate();">
<input type=text size=6 value=0 name="quantity[2]" onBlur="Calculate();">
<b>Total Qty: </b><input value=0 type=text size=7
name="total_qty" readonly>
<input type="submit" value="Submit Locations" /></form>
...and the error message that I'm getting when running the function Calculate() says:
"document.locationsform.quantity.0 is null or not an object"
It seems to be reading the array object number as the value of the field "quantity," a field that, of course, does not exist anywhere in my code.
Did I declare something wrong? What's going on?